Skip to content

Instantly share code, notes, and snippets.

@niczak
Created June 3, 2015 19:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save niczak/ef0219bb36d4a828e7fa to your computer and use it in GitHub Desktop.
function formatBytes($size, $precision = 2)
{
$base = log($size, 1024);
$suffixes = array('', 'k', 'M', 'G', 'T');
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