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 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 849

<?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));
}
?>
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.