The example in this article describes the use of PHP to get folder size functions. Share to everyone for your reference. Specifically as follows:
?
Get folder Size
function Getdirsize ($dir)
{
$handle = Opendir ($dir);
while (false!== ($FolderOrFile = Readdir ($handle)))
{
if ($FolderOrFile!= "." && $FolderOrFile!= "...")
{
if (Is_dir ("$dir/$FolderOrFile"))
{
$sizeResult + + getdirsize ("$dir/$FolderOrFile");
}
Else
{
$sizeResult + + filesize ("$dir/$FolderOrFile");
}
}
}
Closedir ($handle);
return $sizeResult;
}
Unit Automatic conversion function
function Getrealsize ($size)
{
$KB = 1024; Kilobyte
$MB = 1024 * $KB; Megabyte
$GB = 1024 * $MB; Gigabyte
$TB = 1024 * $GB; Terabyte
if ($size < $KB)
{
return $size. " B ";
}
else if ($size < $MB)
{
Return round ($size/$KB, 2). " KB ";
}
else if ($size < $GB)
{
Return round ($size/$MB, 2). " MB ";
}
else if ($size < $TB)
{
Return round ($size/$GB, 2). " GB ";
}
Else
{
Return round ($size/$TB, 2). " TB ";
}
}
Echo getrealsize (getdirsize (' directory to fetch size '));
?>
I hope this article will help you with your PHP program design.