可能重複:
Get the Files inside a directory
PHP: scandir() is too slowPHP最有效的方式列出文件非常大的目錄
我有一個在它的文件數以萬計和目錄我想在頁面上顯示這些文件的列表。我試着用scandir來做這件事,而且這需要永遠。什麼是實現這一目標的有效方法?
可能重複:
Get the Files inside a directory
PHP: scandir() is too slowPHP最有效的方式列出文件非常大的目錄
我有一個在它的文件數以萬計和目錄我想在頁面上顯示這些文件的列表。我試着用scandir來做這件事,而且這需要永遠。什麼是實現這一目標的有效方法?
我沒有基準他們,但你的其他選擇
水珠() - http://php.net/manual/en/function.glob.php
執行opendir() - http://www.php.net/manual/en/function.opendir.php
我推薦'FilesystemIterator'通過'DirectoryIterator'。 – salathe 2011-03-30 08:53:49
@salathe +1 :-) – eisberg 2011-03-30 09:01:49
@salathe +1另請參見問題[DirectoryIterator和FileSystemIterator之間的區別](http://stackoverflow.com/questions/12532064/difference-between-directoryiterator-and-filesystemiterator) 。乾杯;-) – olibre 2014-09-28 20:53:35
$directory=opendir($_SERVER['DOCUMENT_ROOT'].'/directory/');
while ($file = readdir($directory)) {
if($file!="." && $file!=".."){
echo $file."<br>";
}
}
closedir($directory);
整點是,這種方法是太慢 – 2012-11-23 15:49:29
@ValRedchenko我不會那麼肯定在該聲明:http://stackoverflow.com/questions/8692764/readdir-vs-scandir – topherg 2013-07-09 13:29:15
其中哪些你嘗試過:http://stackoverflow.com/search?q=list+files+directory+php – Gordon 2011-03-30 07:27:16
你也想讀[把水珠來測試(HTTP:// www.phparch.com/2010/04/28/putting-glob-to-the-test/) – Gordon 2011-03-30 07:28:42
我已經嘗試過這些方法 - 他們的工作與罰款千元左右的文件,但它需要一個年齡返回幾十萬的文件到 – John 2011-03-30 07:33:12