Created
February 10, 2019 10:16
-
-
Save AlekVolsk/4601adce948a2d541f54696825668a95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
function file_size($bytes) | |
{ | |
$sfx = [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ]; | |
$base = 1024; | |
$class = min((int)log($bytes, $base), count($sfx) - 1); | |
return sprintf('%1.2f' , $bytes / pow($base, $class)) . ' ' . $sfx[$class]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment