private function filesize bytes format 01d force bytes max int bytes u

1
2
3
4
5
6
7
private function filesize($bytes, $format = '%01d %s', $force = '') {
$bytes = max(0, (int) $bytes);
$units = array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
$power = array_search(ucfirst($force), $units);
if ($power === false) $power = $bytes > 0 ? floor(log($bytes, 1024)) : 0;
return sprintf($format, $bytes / pow(1024, $power), $units[$power]);
}