<?
/*
Filesize Calculating function
Function by: Czaries [czaries@czaries.net]
Explanation:
Converts a filesize string to a more readable and "human"
format, like KB, MB, GB, and TB, instead of a long string of
numbers. in bytes To be used in conjunction with PHP's
filesize() function.
To get Filesize:
$size = filesize("/path/to/file/file.zip");
Call by:
$size = calcsize($size);
*/
### Retuns the size of a file in a "human" format ###
function calcsize($size) {
$kb=1024;
$mb=1048576;
$gb=1073741824;
$tb=1099511627776;
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";
}
}
?>
Scripts & Programs © 2010 Vance Lucas | Follow me on Twitter