PHP usage example for getting the folder size function,
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.