Home > Backend Development > PHP Tutorial > PHP gets folder list, file list

PHP gets folder list, file list

WBOY
Release: 2016-07-25 09:08:33
Original
1870 people have browsed it
PHP gets folder list, file list
  1. /**
  2. * Goofy 2011-11-30
  3. * getDir() goes to the folder list, and getFile() goes to the file list under the corresponding folder. The difference between the two is to determine whether there are files with a "." suffix. Everything else is the same
  4. */
  5. //Get the file directory list, this method returns an array
  6. function getDir($dir) {
  7. $dirArray[]=NULL;
  8. if ( false != ($handle = opendir ( $dir ))) {
  9. $i=0;
  10. while ( false !== ($file = readdir ( $handle )) ) {
  11. //Remove "".", " .." and files with ".xxx" suffix
  12. if ($file != "." && $file != ".."&&!strpos($file,".")) {
  13. $dirArray[$i | $fileArray[]=NULL;
  14. if (false != ($handle = opendir ( $dir ))) {
  15. $i=0;
  16. while ( false !== ($file = readdir ( $handle )) ) {
  17. //Remove "".", ".." and files with ".xxx" suffix
  18. if ($file != "." && $file != ".."&&strpos($file,".") ) {
  19. $fileArray[$i]="./imageroot/current/".$file;
  20. if($i==100){
  21. break;
  22. }
  23. $i++;
  24. }
  25. }
  26. //Close handle
  27. closedir ( $handle );
  28. }
  29. return $fileArray;
  30. }
  31. //Call method getDir("./dir")......
  32. ?>
  33. Copy code
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template