PHP getting folder size function usage example, _ PHP Tutorial

Source: Internet
Author: User
PHP obtains the folder size function usage instance ,. Example of PHP function usage for getting the folder size. this example describes how to use PHP function for getting the folder size. Share it with you for your reference. Details: php getting folder size PHP getting folder size function usage instance,

This example describes how to use PHP to obtain the folder size function. Share it with you for your reference. The details are as follows:

<? Php // Get the folder size function getDirSize ($ dir) {$ handle = opendir ($ dir); while (false! ==( $ FolderOrFile = readdir ($ handle) {if ($ FolderOrFile! = "." & $ FolderOrFile! = ".. ") {If (is_dir (" $ dir/$ FolderOrFile ") {$ sizeResult + = getDirSize (" $ dir/$ FolderOrFile ");} else {$ sizeResult + = filesize ("$ dir/$ FolderOrFile") ;}} closedir ($ handle); return $ sizeResult ;} // function getRealSize ($ size) {$ kb = 1024; // Kilobyte $ mb = 1024 * $ kb; // Megabyte $ gb = 1024 * $ mb; // Gigabyte $ tb = 1024 * $ gb; // Terabyte if ($ size <$ kb) {return $ size. "B";} else if ($ Size <$ mb) {return round ($ size/$ kb, 2 ). "KB";} else if ($ size <$ gb) {return round ($ size/$ mb, 2 ). "MB";} else if ($ size <$ tb) {return round ($ size/$ gb, 2 ). "GB";} else {return round ($ size/$ tb, 2 ). "TB" ;}} echo getRealSize (getDirSize ('directory to be retrieved size');?>

I hope this article will help you with php programming.

Example: This article describes how to use PHP to obtain the folder size function. Share it with you for your reference. Php // Get the folder size...

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.