function humanFileSize($size)
{
if ($size >= 1073741824) {
$fileSize = round($size / 1024 / 1024 / 1024,1) . 'GB';
} elseif ($size >= 1048576) {
$fileSize = round($size / 1024 / 1024,1) . 'MB';
} elseif($size >= 1024) {
$fileSize = round($size / 1024,1) . 'KB';
} else {
$fileSize = $size . ' bytes';
}
return $fileSize;
}
... отлично работает, за исключением: я не могу вручную выбрать, в каком формате мне нужно отображать, скажем, я хочу показывать в МБ только размер файла. В настоящее время, если он находится в диапазоне GB, он будет отображаться только в GB.
Также, как ограничить десятичное число до 2?