Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php calculate the entire directory size

Shulou Source: shulou.com Published: 2022-06-03 19:41:29 11月12日 Update

This article mainly introduces php how to calculate the size of the entire directory, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The specific implementation methods are as follows:

/ * * Calculate the full size of a directory * * @ author Jonas John * @ version 0.2 * @ param string $DirectoryPath Directory path * / function CalcDirectorySize ($DirectoryPath) {/ / I reccomend using a normalize_path function here / / to make sure $DirectoryPath contains an ending slash / / To display a good looking size you can use 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 ($DirectoryPath. $File. DIRECTORY_SEPARATOR); else $Size + = filesize ($DirectoryPath. $File);} closedir ($Dir); return $Size;} / / use example: $SizeInBytes = CalcDirectorySize ('data/'); Thank you for reading this article carefully. I hope the article "how to calculate the size of the entire directory" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Tags: Articles size catalogue value interest at the same time methods more friends knowledge editing examples industry information information channels channels references learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Apple Microsoft Linux Redmi