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

yipeiwu_com6年前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."
"."
";

相关文章

php fread读取文件注意事项

php fread函数介绍 string fread ( int handle, int length ) fread() 从文件指针 handle 读取最多 length 个字节。...

PHP使用file_get_content设置头信息的方法

本文实例讲述了PHP使用file_get_content设置头信息的方法。分享给大家供大家参考,具体如下: 直接上代码: <?php /** Accept applic...

phpMyAdmin 安装及问题总结

1/无法载入mcrypt扩展,请检查PHP配置; 2/配置文件现在需要绝密的短语密码(blowfish_secret); 3/#2003-服务器没有响应。 由于目前phpMyAdmin的...

PHP实现模拟http请求的方法分析

本文实例讲述了PHP实现模拟http请求的方法。分享给大家供大家参考,具体如下: 在http简析中,我们提到了浏览器请求资源的一个流程,那么这个流程能不能用php来模拟呢?答案是肯定的。...

php 判断页面或图片是否经过gzip压缩的方法

使用php判断页面或图片是否经过gzip压缩方法 1.使用get_headers 页面内容 <?php ob_start('ob_gzhandler'); // 开启...