统计目录里文件总大小的PHP类
时间:2006-12-06 来源:mosquito_2006
/*
可以根据你的需要随意修改。
*/
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"&&$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;
?>
/*
可以根据你的需要随意修改,如果不会改就叫我帮你改好了。
*/
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"&&$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;
?>
相关阅读 更多 +
排行榜 更多 +