开发者

PHP most efficient way to list the files in a very large directory [duplicate]

This question already has answers here: Closed 11 years ago.
开发者_如何学Go

Possible 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜