PHP obtains the folder list, file list-php Tutorial

Source: Internet
Author: User
PHP obtains the folder list and file list.
PHP obtains the folder list and file list.

  1. /**
  2. * Goofy 2011-11-30
  3. * GetDir () is used to go to the folder list, and getFile () is used to go to the file list under the corresponding folder. The difference between the two is to determine whether there are files with the "." suffix, and the others are the same.
  4. */
  5. // Obtain 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 the suffix". xxx"
  12. If ($ file! = "." & $ File! = ".."&&! Strpos ($ file ,".")){
  13. $ DirArray [$ I] = $ file;
  14. $ I ++;
  15. }
  16. }
  17. // Close the handle
  18. Closedir ($ handle );
  19. }
  20. Return $ dirArray;
  21. }
  22. // Obtain the file list
  23. Function getFile ($ dir ){
  24. $ FileArray [] = NULL;
  25. If (false! = ($ Handle = opendir ($ dir ))){
  26. $ I = 0;
  27. While (false! ==( $ File = readdir ($ handle ))){
  28. // Remove "". "," .. ", and files with the suffix". xxx"
  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 the handle
  38. Closedir ($ handle );
  39. }
  40. Return $ fileArray;
  41. }
  42. // Call the getDir ("./dir ")......
  43. ?>

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.