<?
/**
统计目录文件大小的函数
@author xfcode
@link http://www.jbxue.com
*/
function dirsize($dir)
{
@$dh = opendir($dir);
$size = 0;
while ($file = @readdir($dh))
{
if ($file != "." and $file != "..")
{
$path = $dir."/".$file;
if (is_dir($path))
{
$size += dirsize($path);
}
elseif (is_file($path))
{
$size += filesize($path);
}
}
}
@closedir($dh);
return $size;
}
//function end
//eg:
$dir_path = "./my_files";
$dir_size = dirsize($dir_path);
$dir_size = $dir_size/1024/1024;
echo $dir_size."MB";
?>
Salin selepas log masuk