Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active December 18, 2015 09:49
Show Gist options
  • Save remoharsono/5764559 to your computer and use it in GitHub Desktop.
Save remoharsono/5764559 to your computer and use it in GitHub Desktop.
formatting into Kilobytes, Megabytes...//echo formatBytes(24962496);// 23.81M//echo formatBytes(24962496, 0);// 24M//echo formatBytes(24962496, 4);// 23.8061M
function formatBytes($size, $precision = 2)
{
$base = log($size) / log(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