blob: 958c98c80b6ac530b1803412aa05307fa3a3d0d2 [file] [log] [blame]
<?php
namespace App\Util;
class Filesize {
public static function humanReadableFormat(int $filesize): string {
$units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
$power = ($filesize > 0) ? floor(log($filesize, 1024)) : 0;
return sprintf(
'%01.2f %s',
$filesize / pow(1024, $power),
$units[$power]
);
}
}