read-dir-recursive.php 991 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2011 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * return recursive all data from the given directory
  15. * @author banana mail@bananas-playground.net
  16. * @param string $directory The directory to read
  17. * @return array $files
  18. */
  19. function getSubFiles($directory) {
  20. $files = array();
  21. $dh = opendir($directory);
  22. while(false !== ($file = readdir($dh))) {
  23. if($file[0] ==".") continue;
  24. if(is_file($directory."/".$file)) {
  25. array_push($files, $directory."/".$file);
  26. }
  27. else {
  28. $files = array_merge($files, getSubFiles($directory."/".$file));
  29. }
  30. }
  31. closedir($dh);
  32. return $files;
  33. }
  34. ?>