format_size

  1. drupal
    1. 4.7
    2. 5
    3. 6 common.inc
    4. 7 common.inc
Versions
4.7 – 5 format_size($size)
6 – 7 format_size($size, $langcode = NULL)

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

▾ 4 functions call format_size()

fileupload_view in developer/examples/fileupload.module
Implementation of hook_view.
theme_upload_attachments in modules/upload.module
Displays file attachments in table
_upload_form in modules/upload.module
_upload_validate in modules/upload.module

Code

includes/common.inc, line 850

<?php
function format_size($size) {
  $suffix = t('bytes');
  if ($size >= 1024) {
    $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));
}
?>