Home >Backend Development >PHP Tutorial >How to calculate the size of a directory using PHP_PHP Tutorial

How to calculate the size of a directory using PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:54846browse

PHP CURL session COOKIE

can call system commands, or like this:

Copy code The code is as follows:

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.comtruehttp: //www.bkjia.com/PHPjc/748158.htmlTechArticlePHP CURL session COOKIE can call system commands, or like this: Copy the code code as follows: function dirsize($dir) { @$dh = opendir($dir); $size = 0; while ($file = @readdir($d...
Statement:
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