PHP statistics directory in the file and directory size of the method, involving PHP for file and directory traversal, reading and operation of the relevant skills
The examples in this article describe the files in the PHP statistics directory and the size of directories in the directory.
Share to everyone for your reference, as follows:
"; } else{echo "". $fileName. " ===== ". Date (" Y-m-d h:i:s ", Filectime ($file))." = = = ". FileType ($file)." = = = ". Tosize (FileSize ($file))."
"; }}} closedir ($dir); Convert the size of a file or directory into an easy-to-read way function tosize ($size) {$DW;//Specify the unit of file or directory statistics if ($size >pow (2,30)) {$DW = "GB"; $size =round ($size/pow (2,30), 2); } else if ($size >pow (2,20)) {$DW = "MB"; $size =round ($size/pow (2,20), 2); } else if ($size >pow (2,10)) {$DW = "KB"; $size =round ($size/pow (2,10), 2); } else {$dw = "bytes";} return $size. $dw; }//Use recursion to count the size of the directory function dirsize ($dirName) {$dirsize =0; $dir =opendir ($dirName); while ($fileName =readdir ($dir)) {$ file= $dirName. " /". $fileName; if ($fileName! = "." && $fileName! = "...") {//must be judged, otherwise an error will occur if (Is_dir ($file)) {$dirsize +=dirsize ($file); } else{$dirsize +=filesize ($file); }}} closedir ($dir); return $dirsize; }?>
I hope this article is helpful for you to learn PHP.