Exemplo n.º 1
0
/**
 * Utility function to translate a filesize in bytes into a human-readable version.
 *
 * @param int $filesize Filesize in bytes
 * @param int $round Precision to round to
 *
 * @return string
 */
function format_size($filesize, $round = 2) {
	$suf = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
	$c   = 0;
	while ($filesize >= 1024) {
		$c++;
		$filesize = $filesize / 1024;
	}

	return I18NLoader::FormatNumber($filesize, $round) . ' ' . $suf[$c];
}
Exemplo n.º 2
0
/**
 * Display a filesize in a human-readable format.
 *
 * #### Example Usage
 *
 * <pre>
 * {filesize 123} => "123 bytes"
 * {filesize 2048} => "2 kiB"
 * </pre>
 *
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty $smarty  Parent Smarty template object
 *
 * @return string
 * @throws SmartyException
 */
function smarty_function_filespeed($params, $smarty){
	
	$size = $params[0];
	
	$suf = array('bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps');
	$c   = 0;
	while ($size >= 1024) {
		$c++;
		$size = $size / 1024;
	}

	return \Core\i18n\I18NLoader::FormatNumber($size, 1) . ' ' . $suf[$c];
}