Skip to content

Instantly share code, notes, and snippets.

@zoxon
Last active August 29, 2015 13:58
Show Gist options
  • Save zoxon/10368175 to your computer and use it in GitHub Desktop.
Save zoxon/10368175 to your computer and use it in GitHub Desktop.
PHP: Format file size units
public static function formatFileSize($fileSize) {
if ($fileSize >= 1073741824) {
$fileSize = round($fileSize / 1073741824 * 100) / 100 . " " . self::_translate()->_('ГБ');
} elseif ($fileSize >= 1048576) {
$fileSize = round($fileSize / 1048576 * 100) / 100 . " " . self::_translate()->_('МБ');
} elseif ($fileSize >= 1024) {
$fileSize = round($fileSize / 1024 * 100) / 100 . " " . self::_translate()->_('КБ');
} else {
$fileSize = $fileSize . " " . self::_translate()->_('Б');
}
return $fileSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment