<?php
function fm_get_filesize($size)
{
$size = (float) $size;
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]);
}
for ($i = 0; $i < 100; $i++) {
echo fm_get_filesize(pow('102'.rand(4, 100), $i))."\n";
}
preferences:
44.33 ms | 409 KiB | 5 Q