Created
January 21, 2015 08:55
-
-
Save jacquesletesson/6c760d7fe05671cbb5fd to your computer and use it in GitHub Desktop.
Convert bytes to human-friendly unit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------------------------------------------------ | |
// :: 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