Future-proof (for a good while) byte size to string function
function friendlyBytes($size,$pre = 2) {
$sizes = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
for ($i = (count($sizes)); $i > 0; $i--) {
if ($i > 0) {
$exp = pow(1024,$i);
if ($size > $exp) {
return round(($size / $exp),$pre).$sizes[$i];
}
}
}
return $size."B";
}
Comments