Skip to content

Instantly share code, notes, and snippets.

@bogomolov-dev
Created January 28, 2014 13:18
Show Gist options
  • Save bogomolov-dev/8667427 to your computer and use it in GitHub Desktop.
Save bogomolov-dev/8667427 to your computer and use it in GitHub Desktop.
Rechnet die übergebenen Bytes in die nächste passende Einheit um.
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