Home > php教程 > php手册 > 用PHP来计算某个目录大小的方法

用PHP来计算某个目录大小的方法

WBOY
Release: 2016-06-06 20:23:35
Original
1177 people have browsed it

这篇文章主要介绍了用PHP来计算某个目录大小的方法,需要的朋友可以参考下

PHP CURL session COOKIE

可以调用系统命令,,还可以这样:

复制代码 代码如下:


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."
"."
";

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template