用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 return语句的另一个作用

一直以为,return只能出现在函数中,直到看了bbPress的代码: <?php require_once('./bb-load.php'); bb_reperm...

php中模拟POST传递数据的两种方法分享

方法1 复制代码 代码如下: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://192.168.1.135/turntab...

php以post形式发送xml的方法

本文实例讲述了php以post形式发送xml的方法。分享给大家供大家参考。具体方法如下: 方法一,使用curl: 复制代码 代码如下:$xml_data = <xml>......

PHP的中使用非缓冲模式查询数据库的方法

最近在开发一个PHP程序时遇到了下面的错误: PHP Fatal error: Allowed memory size of 268 435 456 bytes exhausted 错误...

php中static和const关键字用法分析

php中static和const关键字用法分析

本文实例讲述了php中static和const关键字用法。分享给大家供大家参考,具体如下: static关键字在类中描述的成员属性和成员函数都是静态的。 static成员能限制外部的访问...