用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字符串word末字符实现大小写互换的方法

本文实例讲述了PHP字符串word末字符实现大小写互换的方法。分享给大家供大家参考。具体实现方法如下: 一、要求: 给出一个字符串如 “A journey of, a thousand...

PHP中使用OpenSSL生成证书及加密解密

依赖于OpenSSL扩展 /*加密解密*/ function authcode($string, $operation = 'E') { $ssl_public = file_g...

php中this关键字用法分析

本文实例讲述了php中this关键字用法。分享给大家供大家参考,具体如下: 下面定义了一个Cart类 <?php class Cart { var $items;...

PHP程序漏洞产生的原因分析与防范方法说明

滥用include 1.漏洞原因: Include是编写PHP网站中最常用的函数,并且支持相对路径。有很多PHP脚本直接把某输入变量作为Include的参数,造成任意引用脚本、绝对路...

php过滤输入操作之htmlentities与htmlspecialchars用法分析

本文实例讲述了php过滤输入操作htmlentities与htmlspecialchars用法。分享给大家供大家参考,具体如下: 过滤输入 (即来自所列数据源中的任何数据)是指,转义或删...