统计目录里文件总大小的PHP类
金东浩博客随机日志
<?
/*
版权所有antplus
QQ:382399212 E-main:antplus@163.com
可以根据你的需要随意修改,如果不会改就叫我帮你改好了。
*/
class sundry
{
function total_size($dir)
{
$filepoint = opendir($dir
static $total_size;
while($file = readdir($filepoint))
{
if($file=="."||$file=="..")continue;
$target = "$dir/$file";
if(is_dir($target))
{
$this->total_size($target
}
else
{
$total_size+= filesize($target
}
}
return $total_size;
}
function size_show($dir)
{
$total_size = $this->total_size($dir
if($total_size<"1024")
$size_show = ($total_size*8)." byte";
if($total_size>"1024"&&$total_size<"1048576")
$size_show = sprintf("%1.2f",($total_size/1024))." K";
if($total_size>"1048576")
$size_show = sprintf("%1.2f",($total_size/1048576))." M";
return $size_show;
}
}
//============
//使用方法
//============
$sundry = new sundry;
//test为你要计算大小的目录
$size = $sundry->size_show("test"
echo $size;
?>
/*
版权所有antplus
QQ:382399212 E-main:antplus@163.com
可以根据你的需要随意修改,如果不会改就叫我帮你改好了。
*/
class sundry
{
function total_size($dir)
{
$filepoint = opendir($dir
static $total_size;
while($file = readdir($filepoint))
{
if($file=="."||$file=="..")continue;
$target = "$dir/$file";
if(is_dir($target))
{
$this->total_size($target
}
else
{
$total_size+= filesize($target
}
}
return $total_size;
}
function size_show($dir)
{
$total_size = $this->total_size($dir
if($total_size<"1024")
$size_show = ($total_size*8)." byte";
if($total_size>"1024"&&$total_size<"1048576")
$size_show = sprintf("%1.2f",($total_size/1024))." K";
if($total_size>"1048576")
$size_show = sprintf("%1.2f",($total_size/1048576))." M";
return $size_show;
}
}
//============
//使用方法
//============
$sundry = new sundry;
//test为你要计算大小的目录
$size = $sundry->size_show("test"
echo $size;
?>
本文来自 我爱贝贝[www.bbmy.net]-金东浩官方网站,如若转载注明出处。
金东浩博客随机日志
![]() 咱不怕累,咱不怕 | ![]() 老婆通知我要育前 | ![]() 我的小宝贝 | ![]() 五一期间给宝宝拍 | ![]() 我老婆的表妹结婚 | ![]() 要洗多少次奶瓶 |
![]() 我家宝宝不怕水 | ![]() 宝宝的第一个儿童 | ![]() 宝宝百日照后的光 | ![]() 胎教音乐mp3下 | ![]() 宝宝会翻身了 | ![]() 宝宝再次发烧 |
![]() 宝宝越来越来难带 | ![]() 宝宝发烧恶搞 | ![]() 宝宝长牙齿了 | ![]() 终于拿到宝宝百日 | ![]() 原来是要学说话了 | ![]() 无题 |