diff options
Diffstat (limited to 'smartyplugins/modifier.display_bytes.php')
| -rw-r--r-- | smartyplugins/modifier.display_bytes.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/smartyplugins/modifier.display_bytes.php b/smartyplugins/modifier.display_bytes.php new file mode 100644 index 0000000..aed6c99 --- /dev/null +++ b/smartyplugins/modifier.display_bytes.php @@ -0,0 +1,26 @@ +<?php +/** + * Smarty plugin + * @package Smarty + * @subpackage plugins + */ + +/** + * Smarty plugin + * ------------------------------------------------------------- + * Type: modifier + * Name: display_bytes + * Purpose: show an integer in a human readable Byte size with optional resolution + * Example: {$someFile|filesize|display_bytes:2} + * ------------------------------------------------------------- + */ +function smarty_modifier_display_bytes( $pSize, $pDecimalPlaces = 1 ) { + $i = 0; + $iec = array( "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ); + while( ( $pSize / 1024 ) > 1 ) { + $pSize = $pSize / 1024; + $i++; + } + return round( $pSize, $pDecimalPlaces )." ".$iec[$i]; +} +?> |
