计算文件夹的大小,包括子文件夹,格式化输出文件夹大小、文件数、子文件夹数信息。<br>
//代码也可以用于统计目录数<br>
//格式化输出目录大小 单位:Bytes,KB,MB,GB<br>
<br>
function getDirectorySize($path)<br>
{<br>
$totalsize = 0;<br>
$totalcount = 0;<br>
$dircount = 0;<br>
if ($handle = opendir ($path))<br>
{<br>
while (false !== ($file = readdir($handle)))<br>
{<br>
$nextpath = $path . '/' . $file;<br>
if ($file != '.' && $file != '..' && !is_link ($nextpath))<br>
{<br>
if (is_dir ($nextpath))<br>
{<br>
$dircount++;<br>
$result = getDirectorySize($nextpath);<br>
$totalsize += $result['size'];<br>
$totalcount += $result['count'];<br>
$dircount += $result['dircount'];<br>
}<br>
elseif (is_file ($nextpath))<br>
{<br>
$totalsize += filesize ($nextpath);<br>
$totalcount++;<br>
}<br>
}<br>
}<br>
}<br>
closedir ($handle);<br>
$total['size'] = $totalsize;<br>
$total['count'] = $totalcount;<br>
$total['dircount'] = $dircount;<br>
return $total;<br>
}<br>
<br>
function sizeFormat($size)<br>
{<br>
$sizeStr='';<br>
if($size
{<br>
return $size." bytes";<br>
}<br>
else if($size
{<br>
$size=round($size/1024,1);<br>
return $size." KB";<br>
}<br>
else if($size
{<br>
$size=round($size/(1024*1024),1);<br>
return $size." MB";<br>
}<br>
else<br>
{<br>
$size=round($size/(1024*1024*1024),1);<br>
return $size." GB";<br>
}<br>
<br>
}<br>
<br>
$path="/home/www/htdocs";<br>
$ar=getDirectorySize($path);<br>
<br>
echo "<h4 id="路径-path">路径 : $path</h4>";<br>
echo "目录大小 : ".sizeFormat($ar['size'])."<br>";<br>
echo "文件数 : ".$ar['count']."<br>";<br>
echo "目录术 : ".$ar['dircount']."<br>";<br>
<br>
//print_r($ar);<br>
?>
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)