Displaying file sizes in human readable format
Posted on June 27, 2002 by snipe in PHP/mySQL
This code prints out “b” for bytes, “m” for megs, etc depending on the file size.
= 1073741824) {
$fileweight = round($fileweight / 1073741824 * 100) / 100 . "GB";
} elseif ($fileweight >= 1048576) {
$fileweight = round($fileweight / 1048576 * 100) / 100 . "MG";
} elseif ($fileweight >= 1024) {
$fileweight = round($fileweight / 1024 * 100) / 100 . "k";
} else {
$fileweight = $fileweight . "b";
}
return $fileweight;
} // end function
?>
Also check out:
If you think this article kicked ass, subscribe to the RSS feed or follow me on Twitter! Share with your friends, or leave a comment below (or better still, do both!) My entire concept of self-worth is in your hands, so that makes you kind of a big deal. Srsly.


