Skip to content

Instantly share code, notes, and snippets.

@jorijn
Created January 16, 2013 06:01
Show Gist options
  • Select an option

  • Save jorijn/4545007 to your computer and use it in GitHub Desktop.

Select an option

Save jorijn/4545007 to your computer and use it in GitHub Desktop.
formats filesize
function filesize_formatted($path, $rounding = 2)
{
$size = filesize($path);
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), $rounding, '.', ',') . "\xC2\xA0" . $units[$power];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment