Files
kupshop/class/smarty_plugins/modifier.filesize.php
2025-08-02 16:30:27 +02:00

26 lines
516 B
PHP

<?php
/**
* Smarty plugin.
*/
/**
* Smarty filesize modifier plugin.
*
* Type: modifier
* Name: filesize
* Purpose: show the filesize of a file in kb, mb, gb etc...
*
* @param string $
*
* @return string
*/
function smarty_modifier_filesize($size)
{
$size = max(0, (int) $size);
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',').' '.$units[$power];
}