Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file modifier.display_bytes.php

Documentation is available at modifier.display_bytes.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty plugin
  10.  * -------------------------------------------------------------
  11.  * Type:     modifier
  12.  * Name:     display_bytes
  13.  * Purpose:  show an integer in a human readable Byte size with optional resolution
  14.  * Example:  {$someFile|filesize|display_bytes:2}
  15.  * -------------------------------------------------------------
  16.  */
  17. function smarty_modifier_display_bytes( $pSize, $pDecimalPlaces = 1 ) {
  18.     $i = 0;
  19.     $iec = array( "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" );
  20.     while( ( $pSize / 1024 ) > 1 ) {
  21.         $pSize = $pSize / 1024;
  22.         $i++;
  23.     }
  24.     return round( $pSize, $pDecimalPlaces )." ".$iec[$i];
  25. }
  26. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:09 +0000 by phpDocumentor 1.5.0-lsces