/*
*@dirPath 被查询目录的全路径
*@storage 保存文件所占磁盘大小的变量
*
* eg:$storage = dirStorage('/var/www/user');//查看/var/www/user 文件夹所占的大小
*/
function dirStorage( $dirPath , $storage=0){
$dir = opendir($dirPath);
while( false !== ( $file = readdir($dir) ) ){
if( substr($file, 0, 1) === '.') continue;
if( filetype($dirPath.DS.$file) == 'dir' ){
return $this->dirStorage($dirPath.DS.$file, $storage);
}else{
$storage += intval( filesize($dirPath.DS.$file) );
}
}
closedir($dir);
return $storage;
}