我運行PHP版本5.2.11致命錯誤:未捕獲的異常 '的RuntimeException'
當我運行下面的功能:
function get_dirs($path = '.') {
$dirs = array();
foreach (new DirectoryIterator($path) as $file) { // This is line 462.
if ($file->isDir() && !$file->isDot()) {
$dirs[] = $file->getFilename();
}
}
return $dirs;
}
我得到這個錯誤:
Fatal error: Uncaught exception 'RuntimeException' with message 'DirectoryIterator::__construct(/home/test/test.com/wp-content/themes/mytheme/images) [<a href='directoryiterator.--construct'>directoryiterator.--construct</a>]: failed to open dir: No such file or directory' in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php:462 Stack trace: #0 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(462): DirectoryIterator->__construct('/home/test/wie...') #1 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(31): get_dirs('/home/test/wie...') #2 /home/test/test.com/testing123/wp-settings.php(717): include('/home/test/wie...') #3 /home/test/test.com/testing123/wp-config.php(76): require_once('/home/test/wie...') #4 /home/test/test.com/testing123/wp-load.php(30): require_once('/home/test/wie...') #5 /home/test/test.com/testing123 in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php on line 462
更新:我發現這裏的問題是主題安裝在主URL的虛擬目錄下。我的腳本期望主題安裝在主根網址之外。
例如,在這種情況下,主題是安裝在:http://www.example.com/testing123/wp-content/themes/mytheme
不過,我期待這樣的:http://www.example.com/wp-content/themes/mytheme
和SO ...因爲它
我的路徑功能失效不考慮它可以安裝在虛擬目錄下。
我怎麼能在我的這個功能的餵養佔這個場景?
$mydir = get_dirs("$_SERVER[DOCUMENT_ROOT]/wp-content/themes/mytheme/images");
function get_dirs ($path = '.') {
$dirs = array();
foreach (new DirectoryIterator($path) as $file) {
if ($file->isDir() && !$file->isDot()) {
$dirs[] = $file->getFilename();
}
}
return $dirs;
}
如果它說,它未能打開你的圖片目錄,你爲什麼認爲錯誤在編碼中? – 2009-12-23 17:34:37
呃......它看起來像無法找到目錄,它沒有實例化DirectoryIterator的問題。 – mozillalives 2009-12-23 17:35:37