/*
* http://aidanlister.com/repos/v/function.size_readable.php
*/
public static function getFileSizeReadable($size, $retstring = null, $onlyMB = false)
{
if ($onlyMB) {
$sizes = array('B', 'kB', 'MB');
} else {
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
}
if ($retstring === null) {
$retstring = '%01.2f %s';
}
$lastsizestring = end($sizes);
foreach ($sizes as $sizestring) {
if ($size < 1024) {
break;
}
if ($sizestring != $lastsizestring) {
$size /= 1024;
}
}
if ($sizestring == $sizes[0]) {
$retstring = '%01d %s';
}
// Bytes aren't normally fractional
return sprintf($retstring, $size, $sizestring);
}