//************************************** // Name: Dir_Size - Recursively get the size of a directory // Description:Uses recursion to scan a directory and all subdirectories to get the total size of all files residing within. // By: Daniel Green // // // Inputs:The only parameter is the root directory. // // Returns:Returns the total size of the directory and all contents. // //Assumes:Make sure you set $g_dirsize = 0; before calling the function a second time. // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.1186/lngWId.8/qx/vb/scripts/ShowCode.htm //for details. //************************************** $g_dirsize = 0; function dir_size($dir) { global $g_dirsize; $handle = opendir($dir); while($file = readdir($handle)) { if($file != "." && $file != "..") { if(is_dir($dir . "/" . $file)) { dir_size($dir . "/" . $file); }else{ $g_dirsize += filesize($dir . "/" . $file); } } } return($g_dirsize); }