Skip to content

Instantly share code, notes, and snippets.

@dnikonov
Created June 9, 2020 10:16
Show Gist options
  • Save dnikonov/2d9f61f9ea376adc50838385fd923b06 to your computer and use it in GitHub Desktop.
Save dnikonov/2d9f61f9ea376adc50838385fd923b06 to your computer and use it in GitHub Desktop.
if (!function_exists('human_filesize')) {
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . " " . @$sz[$factor] . "B";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment