Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created January 4, 2012 10:33
Show Gist options
  • Save cognitom/1559484 to your computer and use it in GitHub Desktop.
Save cognitom/1559484 to your computer and use it in GitHub Desktop.
バイト数を分かり易い表記に
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