Get Directory List PHP


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



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.