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 = 1024x768 * $KB; Megabyte
$GB = 1024x768 * $MB; Gigabyte
$TB = 1024x768 * $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 (dirname ($_server[script_filename))./include/);
?>
#########################################################
function Dirsize ($dir)
//{
$handle =opendir ($dir);
$size = 0;
while ($file =readdir ($handle))
// {
if ($file = = ".") | | ($file = = "..") ) continue;
if (Is_dir ("$dir/$file"))
$size + = dirsize ("$dir/$file");
Else
$size + = filesize ("$dir/$file");
// }
Closedir ($handle);
return $size;
//}
$big =dirsize (DirName ($_server[script_filename]). " /");
Echo $big;
The result is two digits after the decimal point.
$big *1024 to get the unit kb
http://www.bkjia.com/PHPjc/486551.html www.bkjia.com true http://www.bkjia.com/PHPjc/486551.html techarticle php function Getdirsize ($dir) {$handle = Opendir ($dir), while (false!== ($FolderOrFile = Readdir ($handle))) {if ($Fol Derorfile! =. $FolderOrFile! =.) {if (Is_dir ($dir/$FolderOr ...