112 |
function smarty_mod_filesize($file,$dir,$unit="") |
function smarty_mod_filesize($file,$dir,$unit="") |
113 |
{ |
{ |
114 |
$path=dirname($GLOBALS[SCRIPT_FILENAME])."/$dir/$file"; |
$path=dirname($GLOBALS[SCRIPT_FILENAME])."/$dir/$file"; |
115 |
|
$ext=explode(".",$file); |
116 |
|
$ext=strtoupper(array_pop($ext)); |
117 |
|
|
118 |
if ($size=filesize($path)) { |
if ($size=filesize($path)) { |
119 |
switch ($unit) { |
switch ($unit) { |
120 |
case 'Mb': |
case 'Mb': |
121 |
case 'mb': |
case 'mb': |
122 |
return sprintf("%2.1f Mb",$size/(1024*1024)); |
return sprintf("%s, %2.1f Mb",$ext,$size/(1024*1024)); |
123 |
case 'Kb': |
case 'Kb': |
124 |
case 'kb': |
case 'kb': |
125 |
return sprintf("%2.1f Mb",$size/1024); |
return sprintf("%s, %2.1f Mb",$ext,$size/1024); |
126 |
case 'auto': |
case 'auto': |
127 |
$size=$size/1024; # Kb |
$size=$size/1024; # Kb |
128 |
if ($size > 1024) { |
if ($size > 1024) { |
129 |
return sprintf("%2.1f Mb",$size/1024); |
return sprintf("%s, %2.1f Mb",$ext,$size/1024); |
130 |
} else { |
} else { |
131 |
return sprintf("%2.1f Kb",$size); |
return sprintf("%s, %2.1f Kb",$ext,$size); |
132 |
} |
} |
133 |
|
|
134 |
} |
} |