PHP - 获取目录的大小 [英] PHP – get the size of a directory
本文介绍了PHP - 获取目录的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
$ bytes = 0;
$ iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ dir));
foreach($ iterator as $ i)
{
$ bytes + = $ i-> getSize();
}
What is the best way to get the size of a directory in PHP? I'm looking for a lightweight way to do this since the directories I'll use this for are pretty huge.
There already was a question about this on SO, but it's three years old and the solutions are outdated.(Nowadays fopen
is disabled for security reasons.)
解决方案
Is the RecursiveDirectoryIterator available to you?
$bytes = 0;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
foreach ($iterator as $i)
{
$bytes += $i->getSize();
}
这篇关于PHP - 获取目录的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文