format_size

Versions
4.6 – 5
format_size($size)
6 – 7
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 functions call 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.
file_save_upload in includes/file.inc
Saves a file upload to a new location. The source file is validated as a proper upload and handled as such.
file_validate_size in includes/file.inc
Check that the file's size is below certain limits. This check is not enforced for the user #1.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table
upload_admin_settings in modules/upload/upload.admin.inc
Menu callback for the upload settings form.
upload_admin_settings_validate in modules/upload/upload.admin.inc
Form API callback to validate the upload settings form.
_upload_form in modules/upload/upload.module

Code

includes/common.inc, line 1231

<?php
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);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.