PHP obtains the folder size calculation file .? PhpfunctiongetDirSize ($ dir) {$ handleopendir ($ dir); while (false! ($ FolderOrFilereaddir ($ handle) {if ($ FolderOrFile !. $ FolderOrFile !..) {If (is_dir ($ dir $ FolderOr
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;
}
// Automatic unit 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 (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 is measured in KB.
Http://www.bkjia.com/PHPjc/486551.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486551.htmlTechArticle? Php function getDirSize ($ dir) {$ handle = opendir ($ dir); while (false! ==( $ FolderOrFile = readdir ($ handle) {if ($ FolderOrFile! =. $ FolderOrFile! =...) {If (is_dir ($ dir/$ FolderOr...