Last active
July 7, 2019 21:53
-
-
Save kazimolmez/69c4a1c73b0af955d22e3190d315e271 to your computer and use it in GitHub Desktop.
Php file size format
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
function formatBytes($bytes, $precision = 2) { | |
$units = array("b", "kb", "mb", "gb", "tb"); | |
$bytes = max($bytes, 0); | |
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); | |
$pow = min($pow, count($units) - 1); | |
$bytes /= (1 << (10 * $pow)); | |
return round($bytes, $precision) . " " . $units[$pow]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment