问一个很无知的问题..如何获得一个目录的大小... 用print_r()函数打印相关的目录..得到你要的信息. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不过print_r()好象要php4.3.0h后的版本才支持.. *nix下可以直接执行系统命令system('du -s /home');win下面好像没有直接的命令,可以用下面的函数。<?phpfunction GetDirSize($dir){ $tmp=`dir /S /-C $dir`; preg_match_all('/\d{4}\-\d{2}-\d{2}\s*\d{2}:\d{2}\s*(\d+)\s*(.*)/i', $tmp, $arr); return array_sum($arr[1]);}echo GetDirSize('d:\backup');?> 用递归实现,速度稍慢,包括子目录<?phpecho dirsize('c:/winnt');function dirsize($path){ $path = preg_replace('/[\/\\\]$|$/','/',$path); $handle = dir($path); while (($file = $handle->read()) !== false) { if (is_file($path.$file)) { $filesize += filesize($path.$file); } elseif (($file != '.' && $file != '..')) { $filesize += dirsize($path.$file); } } $handle->close(); return $filesize;}?> 再加个是否包括子目录,默认包括。function dirsize($path,$S=true){ $path = preg_replace('/[\/\\\]$|$/','/',$path); $handle = dir($path); while (($file = $handle->read()) !== false) { if (is_file($path.$file)) { $filesize += filesize($path.$file); } elseif ($S && ($file != '.' && $file != '..')) { $filesize += dirsize($path.$file); } } $handle->close(); return $filesize;} 新学PHP遇到问题了,请教高手。。。 perl-DB 的安装 php insert关于id的问题!! PHP生成的图片(文件流)如何保存到指定文件夹呢? windows2003下的乱码如何解决 这个是怎么做的,用自己的数据库吗? php+mysql优化搜索引擎的搜索结果【有酬】 做了一套成绩查询,管理系统,大家PP看 PHP错误处理 tomcat + php 怎麼配置虛擬目錄? 百思不得其解的问题 这个action提交到哪个页面
system('du -s /home');
win下面好像没有直接的命令,可以用下面的函数。
<?php
function GetDirSize($dir){
$tmp=`dir /S /-C $dir`;
preg_match_all('/\d{4}\-\d{2}-\d{2}\s*\d{2}:\d{2}\s*(\d+)\s*(.*)/i', $tmp, $arr);
return array_sum($arr[1]);
}
echo GetDirSize('d:\backup');
?>
<?php
echo dirsize('c:/winnt');function dirsize($path)
{
$path = preg_replace('/[\/\\\]$|$/','/',$path);
$handle = dir($path);
while (($file = $handle->read()) !== false)
{
if (is_file($path.$file))
{
$filesize += filesize($path.$file);
}
elseif (($file != '.' && $file != '..'))
{
$filesize += dirsize($path.$file);
}
}
$handle->close();
return $filesize;
}
?>
{
$path = preg_replace('/[\/\\\]$|$/','/',$path);
$handle = dir($path);
while (($file = $handle->read()) !== false)
{
if (is_file($path.$file))
{
$filesize += filesize($path.$file);
}
elseif ($S && ($file != '.' && $file != '..'))
{
$filesize += dirsize($path.$file);
}
}
$handle->close();
return $filesize;
}