Created
January 4, 2012 10:33
-
-
Save cognitom/1559484 to your computer and use it in GitHub Desktop.
バイト数を分かり易い表記に
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function byte2str($size){ | |
$kb=1024; | |
$mb=1048576; | |
$gb=1073741824; | |
$tb=1099511627776; | |
if(!$size) return '0 B'; | |
elseif($size<$kb) return $size.' B'; | |
elseif($size<$mb) return round($size/$kb, 0).' KB'; | |
elseif($size<$gb) return round($size/$mb, 2).' MB'; | |
elseif($size<$tb) return round($size/$gb, 2).' GB'; | |
else return round($size/$tb, 2).' TB'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment