Created
January 28, 2014 13:18
-
-
Save bogomolov-dev/8667427 to your computer and use it in GitHub Desktop.
Rechnet die übergebenen Bytes in die nächste passende Einheit um.
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 formatFileSize($bytes) | |
{ | |
$units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); | |
$result = "0.00 B"; | |
if($bytes > 0) | |
{ | |
$result = log($bytes) / log(1024); | |
$index = floor($result); | |
$result = round(pow(1024, $result - ($index)), 2)." ".$units[$index]; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment