This article mainly introduces the method of PHP for folder operation, the interested friend's reference, I hope to help you.
This article describes the PHP Get folder size function usage, specifically as follows:
<?php//Get 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; }//Unit auto CONVERT function getrealsize ($size) {$kb = 1024; Kilobyte $MB = 1024x768 * $KB; Megabyte $GB = 1024x768 * $MB; Gigabyte $TB = 1024x768 * $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 (' need to get the size of the directory '));?
Summary: the above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP-based method for skin changing with cookies
PHP methods for file manipulation and string encryption
PHP Delete, convert, group, sort for arrays