0

Is there a faster way to display a list of files by reading the directory than glob? This works great for a few files but is very slow to display when there is alot of files in a directory?

<ul>
        <?php
            foreach (glob("directory/sub-directory/*.pdf") as $filename) {
            $shortname = basename($filename);
            echo "<LI><span class=file><a href=http://www.mysite.com/directory/sub-directory/viewer.php?doc=$shortname>$shortname</a></span></li>\n";
            }
        ?>
</ul>
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

1 Answers1

0

opendir() is a little bit faster I guess. How many files do you consider a lot? You might want to think about fetching only chunks of the files in the directory, loading the next chunk whenever the user scrolls to the bottom or the like.

Marco Kerwitz
  • 5,294
  • 2
  • 18
  • 17