Last active
September 10, 2015 15:19
-
-
Save tux-00/9508092 to your computer and use it in GitHub Desktop.
Format bytes to kb Mb Gb or Tb automaticaly.
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
<?php | |
function formatBytes($size, $precision = 2) | |
{ | |
if($size== 0) { | |
return 0; | |
} | |
$base = log($size) / log(1024); | |
$suffixes = array('o', 'kb', 'Mb', 'Gb', 'Tb'); | |
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment