php 讀取資料夾與資料夾中檔案的函數

WBOY
發布: 2016-07-25 08:55:57
原創
1210 人瀏覽過
  1. /**

  2. * 读取文件夹及其中文件的函数
  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. }

复制代码

您可能感兴趣的文章: php遍历文件夹下并实现编辑与删除的代码 php获取文件夹大小的函数 Php删除指定文件与文件夹的方法 PHP遍历文件和文件夹的小例子 php获取文件夹信息的统计函数 php计算指定文件夹信息(文件夹数,文件数,文件夹大小)的代码 php遍历目录下所有文件和子文件夹的代码 php遍历文件夹及其下所有文件的代码 计算文件夹大小的php代码



來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!