Skip to content

Instantly share code, notes, and snippets.

@jacquesletesson
Created January 21, 2015 08:55
Show Gist options
  • Save jacquesletesson/6c760d7fe05671cbb5fd to your computer and use it in GitHub Desktop.
Save jacquesletesson/6c760d7fe05671cbb5fd to your computer and use it in GitHub Desktop.
Convert bytes to human-friendly unit
// ------------------------------------------------------------
// :: Convert bytes to human-friendly unit
// :: Source: http://php.net/manual/en/function.filesize.php#106569
// ------------------------------------------------------------
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment