Php functions for reading files in folders and folders

Source: Internet
Author: User
Php functions for reading files in folders and folders

  1. /**

  2. * Functions used to read folders and files
  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 will 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. }

Articles you may be interested in: php traverses the folder and implements code editing and deletion. php obtains the folder size. Php deletes the specified file and folder. PHP traverses the file and folder. small example. php retrieves the folder information. statistical function. php calculates the specified folder information (number of folders, number of files, folder size) code php traverses all files and subfolders under the Directory code php traverses the folder and all files under the code to calculate the php code of the folder size

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.