php計算整個目錄大小的方法
更新時間:2015年06月19日 16:17:50 作者:不吃皮蛋
這篇文章主要介紹了php計算整個目錄大小的方法,涉及php針對目錄操作的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了php計算整個目錄大小的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
/** * Calculate the full size of a directory * * @author Jonas John * @version 0.2 * @param string $DirectoryPath Directory path */ function CalcDirectorySize($DirectoryPath) { // I reccomend using a normalize_path function here // to make sure $DirectoryPath contains an ending slash // To display a good looking size you can use a readable_filesize // function. $Size = 0; $Dir = opendir($DirectoryPath); if (!$Dir) return -1; while (($File = readdir($Dir)) !== false) { // Skip file pointers if ($File[0] == '.') continue; // Go recursive down, or add the file size if (is_dir($DirectoryPath . $File)) $Size += CalcDirectorySize($DirectoryPath . $File . DIRECTORY_SEPARATOR); else $Size += filesize($DirectoryPath . $File); } closedir($Dir); return $Size; } //使用范例: $SizeInBytes = CalcDirectorySize('data/');
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
通用PHP動態(tài)生成靜態(tài)HTML網(wǎng)頁的代碼
最近研究PHP的一些開發(fā)技術(shù),發(fā)現(xiàn)PHP有很多ASP所沒有的優(yōu)秀功能,可以完成一些以前無法完成的功能,例如動態(tài)生成HTML靜態(tài)頁面,以減少服務(wù)器CPU的負載,提高用戶訪問的速度。2010-03-03PHP實現(xiàn)15位身份證號轉(zhuǎn)18位的方法分析
這篇文章主要介紹了PHP實現(xiàn)15位身份證號轉(zhuǎn)18位的方法,結(jié)合實例形式分析了15位身份證號轉(zhuǎn)18位的相關(guān)原理與php實現(xiàn)技巧,需要的朋友可以參考下2019-10-10CodeIgniter生成網(wǎng)站sitemap地圖的方法
用CodeIgniter只需要三步就可以生成網(wǎng)站sitemap地圖,方法很簡單,大家可以參考一下2013-11-11PHP刪除數(shù)組中指定值的元素常用方法實例分析【4種方法】
這篇文章主要介紹了PHP刪除數(shù)組中指定值的元素常用方法,結(jié)合實例形式對比分析了4種常用的數(shù)組遍歷與元素刪除方法,并總結(jié)分析了相關(guān)算法優(yōu)缺點,需要的朋友可以參考下2018-08-08