国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php計算整個目錄大小的方法

2024-05-04 23:35:47
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php計算整個目錄大小的方法,涉及php遞歸遍歷與文件操作的相關技巧,需要的朋友可以參考下

本文實例講述了php計算整個目錄大小的方法。分享給大家供大家參考。具體實現方法如下:

 

 
  1. /** 
  2. * Calculate the full size of a directory 
  3. * 
  4. * @author Jonas John 
  5. * @version 0.2 
  6. * @link http://www.jonasjohn.de/snippets/php/dir-size.htm 
  7. * @param string $DirectoryPath Directory path 
  8. */ 
  9. function CalcDirectorySize($DirectoryPath) { 
  10. // I reccomend using a normalize_path function here 
  11. // to make sure $DirectoryPath contains an ending slash 
  12. // (-> http://www.jonasjohn.de/snippets/php/normalize-path.htm) 
  13. // To display a good looking size you can use a readable_filesize 
  14. // function. 
  15. // (-> http://www.jonasjohn.de/snippets/php/readable-filesize.htm) 
  16. $Size = 0; 
  17. $Dir = opendir($DirectoryPath); 
  18. if (!$Dir
  19. return -1; 
  20. while (($File = readdir($Dir)) !== false) { 
  21. // Skip file pointers 
  22. if ($File[0] == '.'continue;  
  23. // Go recursive down, or add the file size 
  24. if (is_dir($DirectoryPath . $File))  
  25. $Size += CalcDirectorySize($DirectoryPath . $File . DIRECTORY_SEPARATOR); 
  26. else 
  27. $Size += filesize($DirectoryPath . $File);  
  28. closedir($Dir); 
  29. return $Size
  30. //使用范例: 
  31. $SizeInBytes = CalcDirectorySize('data/'); 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 元阳县| 将乐县| 海盐县| 连南| 巴林左旗| 淮滨县| 常州市| 新津县| 上饶县| 昌都县| 荆门市| 余庆县| 绥江县| 荃湾区| 边坝县| 广元市| 梅河口市| 辽宁省| 招远市| 临洮县| 成武县| 司法| 江孜县| 观塘区| 襄垣县| 麦盖提县| 绥棱县| 常山县| 新郑市| 宣城市| 邓州市| 玉林市| 乐昌市| 成武县| 房山区| 安徽省| 勃利县| 潮州市| 从江县| 龙州县| 泽普县|