This article mainly introduces the method of PHP for directory operation, the interested friend's reference, hope to be helpful to everyone.
This article describes how PHP calculates the entire directory size, in the following ways:
/** * Calculate The full size of a directory * * @author Jonas John * @version 0.2 * @param string $Direct Orypath Directory path */function calcdirectorysize ($DirectoryPath) { //I reccomend using a Normalize_path function here /Sure $DirectoryPath contains an ending slash //To display a good looking size can us e a readable_filesize //function. $Size = 0; $Dir = Opendir ($DirectoryPath); if (! $Dir) return-1; while ($File = Readdir ($Dir))!== false) { //Skip File pointers if ($File [0] = = '. ') continue; Go recursive down, or add the file size if (Is_dir ($DirectoryPath. $File)) $Size + = Calcdirectorysize ($Direc Torypath. $File. Directory_separator); else $Size + = FileSize ($DirectoryPath. $File); } Closedir ($Dir); return $Size;} Example of use: $SizeInBytes = calcdirectorysize (' data/');
Summary: the above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
Implementation techniques of PHP unordered tree
PHP Process Control and mathematical operations
PHP sends post, get requests, and action cookies based on Curl