PHP计算一个文件夹的大小
时间:2021-07-01 10:21:17
帮助过:12人阅读
http://blog.1dnet.net/?post=839
- //http://blog.1dnet.net
- function dirSize($directoty){
- $dir_size=0;
- if($dir_handle=@opendir($directoty))
- {
- while($filename=readdir($dir_handle)){
- $subFile=$directoty.DIRECTORY_SEPARATOR.$filename;
- if($filename=='.'||$filename=='..'){
- continue;
- }elseif (is_dir($subFile))
- {
- $dir_size+=dirSize($subFile);
- }elseif (is_file($subFile)){
- $dir_size+=filesize($subFile);
- }
- }
- closedir($dir_handle);
- }
- return ($dir_size);
- }
- $dir_size=dirSize("xym");
- echo round($dir_size/pow(1024,1),2)."KB";
- ?>
|