Use PHP to calculate the size of a directory_PHP tutorial

WBOY
Release: 2016-07-13 17:32:52
Original
752 people have browsed it

You can call system commands, or like this:
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."
"."
";

www.bkjia.com true http: //www.bkjia.com/PHPjc/508660.html TechArticle You can call system commands, you can also do this: function dirsize(dir) @dh = opendir(dir); size = 0; while (file = @readdir(dh)) if (file != "." and file != "..") path = dir."/".file;...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn