function formatFileSize($bytes) { $kiloBytes = ($bytes / 1024); if($kiloBytes > 1023) { $megaBytes = $kiloBytes / 1024; if($megaBytes > 1023) { $gigaBytes = $megaBytes / 1024; if($gigaBytes > 1023) // Lets hope not! { $teraBytes = $gigaBytes / 1024; return round($teraBytes, 2)." TB"; } else return round($gigaBytes, 2)." GB"; } else return round($megaBytes, 2)." MB"; } else return round($kiloBytes, 2)." KB"; }