Same name and namespace in other branches
  1. 10 core/includes/common.inc \format_size()
  2. 4.6.x includes/common.inc \format_size()
  3. 4.7.x includes/common.inc \format_size()
  4. 6.x includes/common.inc \format_size()
  5. 7.x includes/common.inc \format_size()
  6. 8.9.x core/includes/common.inc \format_size()
  7. 9 core/includes/common.inc \format_size()

Generate a string representation for the given byte count.

Parameters

$size: The size in bytes.

Return value

A translated string representation of the size.

Related topics

8 calls to format_size()
blogapi_admin_settings in modules/blogapi/blogapi.module
blogapi_metaweblog_new_media_object in modules/blogapi/blogapi.module
Blogging API callback. Inserts a file into Drupal.
color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
fileupload_view in developer/examples/fileupload.module
Implementation of hook_view.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table

... See full list

File

includes/common.inc, line 1145
Common functions that many Drupal modules will need to reference.

Code

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