Categories
Latest
Popular

Displaying file sizes in human readable format

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
?>