PHP Get Folder List, file list

Source: Internet
Author: User
PHP Get Folder List, file list
  1. /**
  2. * Goofy 2011-11-30
  3. * Getdir () go to the Folder List, GetFile () go to the corresponding folder below the file list, the difference is that there is no "." Suffix file, the others are the same
  4. */
  5. Gets the file directory list, which returns the 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 the ".", ".." and files with a ". xxx" suffix
  12. if ($file! = "." && $file! = "..." &&!strpos ($file, ".")) {
  13. $dirArray [$i]= $file;
  14. $i + +;
  15. }
  16. }
  17. Close handle
  18. Closedir ($handle);
  19. }
  20. return $dirArray;
  21. }
  22. Get a list of files
  23. function GetFile ($dir) {
  24. $fileArray []=null;
  25. if (false! = ($handle = Opendir ($dir))) {
  26. $i = 0;
  27. while (false!== ($file = Readdir ($handle))) {
  28. Remove the ".", ".." and files with a ". xxx" suffix
  29. if ($file! = "." && $file! = "..." &&strpos ($file, ".")) {
  30. $fileArray [$i]= "./imageroot/current/". $file;
  31. if ($i ==100) {
  32. Break
  33. }
  34. $i + +;
  35. }
  36. }
  37. Close handle
  38. Closedir ($handle);
  39. }
  40. return $fileArray;
  41. }
  42. Call Method Getdir ("./dir") ...
  43. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.