How many files in the PHP statistics directory and the size of directories in the directory

Source: Internet
Author: User
Tags pow

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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.