Convert the size in bytes for a file into a more user-friendly format. Simply send the data in bytes to this function:
<?php
function formatfilesize($data) {
// Bytes
if($data < 1024) {
return $data . " bytes";
}
// Kilobytes
else if($data < 1024000) {
return round(($data / 1024 ), 1) . "k";
}
// Megabytes
else {
return round(($data / 1024000), 1) . "MB";
}
}
?>
Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.