//计算目录大小
function directorySize($directory){
$directorySize=0;
//打开目录读取内容
if($dh = opendir($directory)){
//迭代处理每个目录项
while(($filename = readdir($dh))){
//过滤上级栏目和本级栏目
if($filename =="." || $filename =="..") continue;
//开始递归
if(is_dir($directory."/".$filename)){
$directorySize += directorySize($directory."/".$filename);
}else{
//确定文件大小 并且添加到总大小
$directorySize += filesize($directory."/".$filename);
}
}
}
closedir($directory);
return $directorySize;
}
$directory = "templets/default1";
$totalSize = round(directorySize($directory)/1048579,2);
printf("directory is %s: %f MB!
",$directory,$totalSize);
function directorySize($directory){
$directorySize=0;
//打开目录读取内容
if($dh = opendir($directory)){
//迭代处理每个目录项
while(($filename = readdir($dh))){
//过滤上级栏目和本级栏目
if($filename =="." || $filename =="..") continue;
//开始递归
if(is_dir($directory."/".$filename)){
$directorySize += directorySize($directory."/".$filename);
}else{
//确定文件大小 并且添加到总大小
$directorySize += filesize($directory."/".$filename);
}
}
}
closedir($directory);
return $directorySize;
}
$directory = "templets/default1";
$totalSize = round(directorySize($directory)/1048579,2);
printf("directory is %s: %f MB!
",$directory,$totalSize);