国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 永昌县| 南投市| 连州市| 嘉黎县| 濮阳市| 海林市| 河池市| 安庆市| 本溪| 尼玛县| 山阴县| 穆棱市| 永和县| 洮南市| 汤原县| 兴义市| 哈尔滨市| 连平县| 盐边县| 墨脱县| 林州市| 仪陇县| 昌都县| 灌阳县| 疏附县| 博罗县| 抚顺市| 泸定县| 航空| 肃宁县| 即墨市| 汶川县| 阜城县| 年辖:市辖区| 吴川市| 建阳市| 南澳县| 衡阳市| 通辽市| 松江区| 调兵山市|