blob: 9451471bb3653ee802614a5963cb04112086e07f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?php
namespace Bitweaver\Plugins;
/**
* 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 = [ "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ];
while( ( $pSize / 1024 ) > 1 ) {
$pSize = $pSize / 1024;
$i++;
}
return round( $pSize, $pDecimalPlaces )." ".$iec[$i];
}
|