Posted By

fruehjahr on 01/05/09


Tagged

list files directory


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

will_00
fackz
dsntos
vali29


List files in directory


 / Published in: PHP
 

URL: http://www.laughing-buddha.net/jon/php/dirlist/

  1. function dirList ($directory) {
  2. // create an array to hold directory list
  3. $results = array();
  4.  
  5. // create a handler for the directory
  6. $handler = opendir($directory);
  7.  
  8. // keep going until all files in directory have been read
  9. while ($file = readdir($handler)) {
  10.  
  11. // if $file isn't this directory or its parent,
  12. // add it to the results array
  13. if ($file != '.' && $file != '..')
  14. $results[] = $file;
  15. }
  16.  
  17. // tidy up: close the handler
  18. closedir($handler);
  19.  
  20. // done!
  21. return $results;
  22. }

Report this snippet  

You need to login to post a comment.