function format_size

7.x common.inc format_size($size, $langcode = NULL)
6.x common.inc format_size($size, $langcode = NULL)

Generate a string representation for the given byte count.

Parameters

$size: A size in bytes.

$langcode: Optional language code to translate to a language other than what is used to display the page.

Return value

A translated string representation of the size.

Related topics

9 calls to format_size()
blogapi_admin_settings in drupal-6.x/modules/blogapi/blogapi.module
blogapi_metaweblog_new_media_object in drupal-6.x/modules/blogapi/blogapi.module
Blogging API callback. Inserts a file into Drupal.
color_scheme_form_submit in drupal-6.x/modules/color/color.module
Submit handler for color change form.
file_save_upload in drupal-6.x/includes/file.inc
Saves a file upload to a new location.
file_validate_size in drupal-6.x/includes/file.inc
Check that the file's size is below certain limits. This check is not enforced for the user #1.

... See full list

File

drupal-6.x/includes/common.inc, line 1283
Common functions that many Drupal modules will need to reference.

Code

function format_size($size, $langcode = NULL) {
  if ($size < 1024) {
    return format_plural($size, '1 byte', '@count bytes', array(), $langcode);
  }
  else {
    $size = round($size / 1024, 2);
    $suffix = t('KB', array(), $langcode);
    if ($size >= 1024) {
      $size = round($size / 1024, 2);
      $suffix = t('MB', array(), $langcode);
    }
    return t('@size @suffix', array('@size' => $size, '@suffix' => $suffix), $langcode);
  }
}