PHP most efficient way to list the files in a very large directory [duplicate]
开发者_如何学GoPossible Duplicates:
Get the Files inside a directory PHP: scandir() is too slow
I have a directory with tens of thousands of files in it and I want to display a list of these files on a page. I tried doing it with scandir and it takes forever. What would be an efficient method of achieving this?
I recommend using DirectoryIterator or RecursiveDirectoryIterator.
I haven't benchmarked them, but your other options are
glob() - http://php.net/manual/en/function.glob.php
opendir() - http://www.php.net/manual/en/function.opendir.php
$directory=opendir($_SERVER['DOCUMENT_ROOT'].'/directory/');
while ($file = readdir($directory)) {
if($file!="." && $file!=".."){
echo $file."<br>";
}
}
closedir($directory);
精彩评论