List files in directory


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.