Displaying file sizes in human readable format
Posted on June 27, 2002 by snipe in PHP/mySQL
This post was published 9 years 7 months 1 day ago. There is a chance that some APIs or software versions discussed have changed since this article was written. 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.





