用PHP来计算某个目录的大小_PHP教程
程序员文章站
2022-05-03 08:31:48
...
可以调用系统命令,还可以这样:
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;
}
$bb = "/var/www/lg";
$cc = dirsize("$bb");
$aa = $cc/1024/1024;
echo $aa.MB."
"."
";
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;
}
$bb = "/var/www/lg";
$cc = dirsize("$bb");
$aa = $cc/1024/1024;
echo $aa.MB."
"."
";