PHP遍历目录并返回统计目录大小
<?php
$dirname="test1";
//mkdir($dirname);
//遍历一层目录
functionlistdir($dirname){
$ds=opendir($dirname);
while($file=readdir($ds)){
$path=$dirname.'/'.$file;
if(is_dir($file)){
echo"DIR:".$file."<br>";
if($file!="."&&$file!=".."){
listdir($file);
}
}
else{
echo"FILE:".$file."<br>";
}
}
}
functiontotdir($dirname){//对listdir稍加修改
static$tot=0;
$ds=opendir($dirname);
while($file=readdir($ds)){
$path=$dirname.'/'.$file;
if(is_dir($file)){
//echo"DIR:".$file."<br>";
if($file!="."&&$file!=".."){
$tot+=totdir($file);
}
}
else{
//echo"FILE:".$file."<br>";
$tot+=filesize($path);
}
}
//返回总计
return$tot;
}
listdir($dirname);
echototdir($dirname)."bytes";
?>
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短