如何写一个函数对于文件夹,返回该文件夹中所有文件和子文件夹的字节数。 http://search.csdn.net/Expert/topic/2383/2383886.xml?temp=.9958612选遍历目录,得到每个文件的大小。用filetype()来判断是文件(file)还是目录(dir)用filesize()来得到文件大小。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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;}//END tunction dirsizefunction sizecount($filesize) { //计算出所有文件大小 if($filesize >= 1073741824) { $filesize = round($filesize / 1073741824 * 100) / 100 . ' G'; } elseif($filesize >= 1048576) { $filesize = round($filesize / 1048576 * 100) / 100 . ' M'; } elseif($filesize >= 1024) { $filesize = round($filesize / 1024 * 100) / 100 . ' K'; } else { $filesize = $filesize . ' bytes'; } return $filesize;要的时间调用:$attachsize = dirsize("../SaveHtm");$attachsize = $attachsize ? sizecount($attachsize) : "大小未知"; 指定一个目录就可以了最后echo $attachsize得到的就是你指定目录下所有文件及子文件夹下的所有文件的总大小. 不好意思,函数function sizecount还没结束,我忘记后半边}了在 return $filesize;的后面要加上}//END tunction sizecount才正确. AMH - LNMP虚拟主机面板上线发布。 mysql 【特奇怪】一个类的问题, 请大家帮忙解决 股份与合作问题?? 求助:php和mysql跨服务器如何提高效率? bingofei(bingo),近来领分与帮忙.呵呵呵,又放100分 新手发问:如何能有效防止漏洞的产生? 请教大家一个问题 如何存储订单内容最好? PHP如何安装在PWS上? mysql疑问:将表a中所有tid=5的数据插入到表b(两表结构相同),怎样写mysql语句? 请教:php+mysql+apache+phpMyAdmin的怪问题。
@$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;
}//END tunction dirsizefunction sizecount($filesize) { //计算出所有文件大小
if($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' G';
} elseif($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' M';
} elseif($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' K';
} else {
$filesize = $filesize . ' bytes';
}
return $filesize;
要的时间调用:
$attachsize = dirsize("../SaveHtm");
$attachsize = $attachsize ? sizecount($attachsize) : "大小未知";
最后echo $attachsize得到的就是你指定目录下所有文件及子文件夹下的所有文件的总大小.
在 return $filesize;的后面要加上
}//END tunction sizecount
才正确.