11Jul/123
Human Readable File Size in PHP
public static function iec_file_size($size, $digits=4, $unit=0) {
$units = array('B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');
while($size >= 1024) {
$size /= 1024;
++$unit;
}
return number_format($size, max(0,$digits-strlen((string)intval($size))), null, '').' '.$units[$unit];
}
$units = array('B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');
while($size >= 1024) {
$size /= 1024;
++$unit;
}
return number_format($size, max(0,$digits-strlen((string)intval($size))), null, '').' '.$units[$unit];
}
July 24th, 2012 - 16:47
Very nice !
Worked like a charm
October 11th, 2012 - 08:55
Less readable please
October 11th, 2012 - 17:21
You want a less readable file size? Just output it in bytes then