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

首頁 > 語言 > PHP > 正文

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

2024-09-04 11:42:37
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php計算整個目錄大小的方法,涉及php遞歸遍歷與文件操作的相關(guān)技巧,需要的朋友可以參考下,本文實例講述了php計算整個目錄大小的方法,分享給大家供大家參考,具體實現(xiàn)方法如下:

  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.   } 
  29.   closedir($Dir); 
  30.   return $Size
  31. //使用范例: 
  32. $SizeInBytes = CalcDirectorySize('data/');

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 芜湖市| 临汾市| 邵阳市| 七台河市| 竹溪县| 潮安县| 自贡市| 扎兰屯市| 库车县| 剑河县| 棋牌| 鹿邑县| 蓬安县| 扶风县| 台南市| 扶沟县| 如皋市| 广昌县| 定南县| 贺兰县| 云浮市| 循化| 民勤县| 康定县| 綦江县| 武平县| 福泉市| 平罗县| 西盟| 高清| 荔波县| 黄梅县| 四会市| 呈贡县| 明溪县| 罗城| 濉溪县| 读书| 化隆| 武邑县| 宁德市|