嘿傢伙, 我在這裏誤解了什麼?php directoryIterator問題 - 錯誤的路徑?
$dir = get_bloginfo('template_url').'/images/headers/';
echo $dir;
//ouput: myblog.com/wp-content/themes/mytheme/images/headers
$dir = new DirectoryIterator(get_bloginfo('template_url').'/images/headers/');
echo $dir;
//output: nothing at all! blank page!
控制檯拿出一個是fatal_error:
[26-Apr-2011] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'DirectoryIterator::__construct(http://myblog.com/wp-content/themes/mytheme/images/headers/) [directoryiterator.--construct]: failed to open dir: not implemented' in /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php:3 Stack trace:
0 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php(3):
DirectoryIterator->__construct('http://oberperf...')
1 /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/header.php(69):
include('/Users/myname...')
2 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1112):
require_once('/Users/myname...')
3 /Users/myname/htdocs/myblog.com/wp-includes/theme.php(1088):
load_template('/Users/myname...', true)
4 /Users/myname/htdocs/myblog.com/wp-includes/general-template.php(34):
locate_template(Array, true)
5 /Users/myname in /Users/myname/htdocs/myblog.com/wp-content/themes/mytheme/inc/header-image.php
on line 3
任何想法什麼不順心嗎?
謝謝,這是有道理的。但它不起作用!如果我嘗試你的確切代碼$ dir只是一個「。」。點!沒有路徑在那裏。沒有錯誤被拋出。如果我回顯'get_template_directory()。 '/ images/headers /''它可以正常工作,但是DirectoryIterator不會因爲某種原因獲取該值! – matt 2011-04-26 16:14:27
由DirectoryIterator構造函數返回的變量是DirectoryIterator對象,您將無法將其回顯到屏幕。查看DirectoryIterator文檔以獲得更多關於如何使用它的信息http://us.php.net/manual/en/class.directoryiterator.php – jordanstephens 2011-04-26 19:25:35