This article mainly introduces how to use PHP to obtain the folder size function. The example analyzes php's skills related to Folder operations. For more information, see the example in this article. 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.