Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php calculate the entire directory size

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report