统计目录下文件数及大小
1 private function getFileCacheCount($pathName) 2 { 3 $data = [ 4 5 //文件的个数 6 'num' => 0, 7 8 //文件的大小 9 'size' => 0 10 ]; 11 12 //打开目录 13 $dir = opendir($pathName); 14 while(false !== ($file_name = readdir($dir))){ 15 16 //去掉"."和".." 17 if(!($file_name == "." || $file_name == "..")){ 18 19 //拼接文件路径 20 $fileName = $pathName . "/" . $file_name; 21 if(is_dir($fileName)){ 22 23 //递归循环 24 $subData = $this->getFileCacheCount($fileName); 25 $data['size'] += $subData['size']; 26 $data['num'] += $subData['num']; 27 }else{ 28 $data['size'] += filesize($fileName); 29 $data['num']++; 30 } 31 } 32 } 33 closedir($dir); 34 return $data; 35 }