Inspired by: http://www.phpfront.com/php/Convert-Bytes-to-corresponding-size/Converts number in bytes to the number in bytes, megabytes, gigabytes, terabytes, etc. Works well as far as I can see!
<?php
function humanReadableOctets($octets)
{
$units = array('B', 'kB', 'MB', 'GB', 'TB'); // ...etc
for ($i = 0, $size =$octets; $size>1024; $size=$size/1024)
$i++;
return number_format($size, 2) . ' ' . $units[min($i, count($units) -1 )];
}
?>
