计算某个文件夹所占的磁盘空间大小

来源:互联网 发布:剑灵人女捏脸数据下载 编辑:程序博客网 时间:2024/05/17 02:09
/* *@dirPath  被查询目录的全路径 *@storage 保存文件所占磁盘大小的变量 * * eg:$storage = dirStorage('/var/www/user');//查看/var/www/user 文件夹所占的大小 */function dirStorage( $dirPath ){$dir = opendir($dirPath);while( false !== ( $file = readdir($dir) ) ){if( substr($file, 0, 1) === '.') continue;if( filetype($dirPath.DS.$file) == 'dir' ){$storage += intval( $this->dirStorage($dirPath.DS.$file) );}else{$storage += intval( filesize($dirPath.DS.$file) );}}closedir($dir);return $storage;}