Skip to content

Instantly share code, notes, and snippets.

@Krknv
Created September 28, 2017 10:39
Show Gist options
  • Save Krknv/b0b01b262304a911a3c4d4bbd6a9e5fa to your computer and use it in GitHub Desktop.
Save Krknv/b0b01b262304a911a3c4d4bbd6a9e5fa to your computer and use it in GitHub Desktop.
// PHP filesize MB/KB conversion
function filesize_formatted($path)
{
$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), 2, '.', ',') . ' ' . $units[$power];
}
// https://stackoverflow.com/questions/5501427/php-filesize-mb-kb-conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment