2013-07-05 11 views
3

我嘗試在/images目錄上的所有文件運行,我得到斷開,當我到達構造部分的目錄是在同一個目錄中我的PHP文件:FilesystemIterator不工作

$it = new FilesystemIterator('./images/'); 
foreach ($it as $fileinfo) { 
    echo $fileinfo->getFilename() . "\n"; 
} 

我看到的錯誤是:

PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'FilesystemIterator::__construct(/images/,/images/): The system cannot find the file specified. (code: 2)' in D:\wamp\www\MyHome2\php\images.php:9

+0

文件系統路徑應該是從文件系統根目錄;懷疑你的目錄是從你的網絡服務器htdocs根 –

+0

我現在明白爲什麼它不工作我的PHP文件是在/ php目錄我需要做的事情我需要這樣做../images :) – Canttouchit

回答

3

你(可能)使用絕對路徑時你想要相對路徑。使用

$it = new FilesystemIterator('./images/'); 

或你的情況,你需要「上」移一個文件夾,使用「..」動起來:

$it = new FilesystemIterator('./../images/'); 
+0

不幫助同樣的錯誤 – Canttouchit

+0

@Canttouchit好了,'images'目錄的絕對路徑是什麼? – phihag

+0

D:\ wamp \ www \ MyHome2 \ images它使用絕對路徑,但我想使用相對路徑爲什麼現在使用相對路徑 – Canttouchit

2

您的路徑不存在,您正在使用絕對路徑,將其更改爲相對路徑或提供正確的完整路徑。

舉例絕對:

D:\wamp\www\MyHome2\php\images 

例如相對:

./images/ 

您可以閱讀路徑文件系統在這裏是如何工作的:http://en.wikipedia.org/wiki/Path_(computing)

+0

看看我的最後編輯,添加這個點並沒有幫助。 – Canttouchit