List files in folder


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

This function accept one parameter - string, dir path. It will return a array, containing all files found in this and all its subfolders.


Copy this code and paste it in your HTML
  1. function listing($dir) {
  2. $result = array();
  3. foreach (glob($dir.'/*') as $filename) {
  4. if(is_file($filename)) {
  5. $result[] = $filename;
  6. }
  7. else {
  8.  
  9. $result = array_merge(listing($filename), $result);
  10. }
  11. }
  12. return $result;
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.