format_size

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 format_size($size, $langcode = NULL)

Generate a string representation for the given byte count.

Übergabeparameter

$size A size in bytes.

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

Rückgabewert

A translated string representation of the size.

Verwandte Themen

▾ 15 functions call format_size()

blogapi_admin_settings in modules/blogapi/blogapi.module
Add some settings to the admin_settings form.
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.
CommonSizeTestCase::testCommonFormatSize in modules/simpletest/tests/common.test
Check that format_size() returns the expected string.
CommonSizeTestCase::testCommonParseSizeFormatSize in modules/simpletest/tests/common.test
Cross-test parse_size() and format_size().
curlExec in modules/simpletest/drupal_web_test_case.php
Performs a cURL exec with the specified options after calling curlConnect().
file_save_upload in includes/file.inc
Saves a file upload to a new location.
file_validate_size in includes/file.inc
Check that the file's size is below certain limits.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table
UploadTestCase::testLimit in modules/upload/upload.test
Attempt to upload a file that is larger than the maxsize and see that it fails.
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.
UserPictureTestCase::testWithGDinvalidSize in modules/user/user.test
Do the test: GD Toolkit is installed Picture has invalid size
UserPictureTestCase::testWithoutGDinvalidSize in modules/user/user.test
Do the test: GD Toolkit is not installed Picture has invalid size
_upload_form in modules/upload/upload.module

Code

includes/common.inc, line 1747

<?php
function format_size($size, $langcode = NULL) {
  if ($size < DRUPAL_KILOBYTE) {
    return format_plural($size, '1 byte', '@count bytes', array(), $langcode);
  }
  else {
    $size = $size / DRUPAL_KILOBYTE; // Convert bytes to kilobytes.
    $units = array(
      t('@size KB', array(), $langcode),
      t('@size MB', array(), $langcode),
      t('@size GB', array(), $langcode),
      t('@size TB', array(), $langcode),
      t('@size PB', array(), $langcode),
      t('@size EB', array(), $langcode),
      t('@size ZB', array(), $langcode),
      t('@size YB', array(), $langcode),
    );
    foreach ($units as $unit) {
      if (round($size, 2) >= DRUPAL_KILOBYTE) {
        $size = $size / DRUPAL_KILOBYTE;
      }
      else {
        break;
      }
    }
    return str_replace('@size', round($size, 2), $unit);
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen