PHP functions for reading files in folders and folders

Source: Internet
Author: User
  1. /**

  2. * functions to read folders and files in them
  3. * edit:bbs.it-home.org
  4. *
  5. */
  6. function Getfoldersandfiles ($resourceType, $currentFolder)
  7. {
  8. Map the virtual path to the local server path.
  9. $sServerDir = Servermapfolder ($resourceType, $currentFolder, ' getfoldersandfiles ');

  10. Arrays that'll hold the folders and files names.

  11. $aFolders = Array ();
  12. $aFiles = Array ();

  13. $oCurrentFolder = Opendir ($sServerDir);

  14. while ($sFile = Readdir ($oCurrentFolder))

  15. {
  16. if ($sFile! = '. ' && $sFile! = ' ... ')
  17. {
  18. if (Is_dir ($sServerDir. $sFile))
  19. $aFolders [] = " ;
  20. Else
  21. {
  22. $iFileSize = @filesize ($sServerDir. $sFile);
  23. if (! $iFileSize) {
  24. $iFileSize = 0;
  25. }
  26. if ($iFileSize > 0)
  27. {
  28. $iFileSize = Round ($iFileSize/1024);
  29. if ($iFileSize < 1) $iFileSize = 1;
  30. }

  31. $aFiles [] = " ;

  32. }
  33. }
  34. }

  35. Send the folders

  36. Natcasesort ($aFolders);
  37. Echo ' ;

  38. foreach ($aFolders as $sFolder)

  39. Echo $sFolder;

  40. Echo ';

  41. Send the files

  42. Natcasesort ($aFiles);
  43. Echo ' ;

  44. foreach ($aFiles as $sFiles)

  45. Echo $sFiles;

  46. Echo ';

  47. }

Copy Code

You may be interested in the article: PHP Traversal folder and implement edit and delete code PHP get folder size function PHP Delete the specified files and folders php Small example php traverse files and folders to get folder information statistical function PHP calculates the specified folder information (folder number, number of files , folder size) code PHP traversal directory All files and subfolders code PHP traverse folder and all files under the Code Calculate folder size PHP code

  • Related Article

    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.