统计目录里文件总大小的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;
?>