Human readable file size
This function return formatting of file sizes in a human readable format.
function formatFileSize( $size ) { $file_size = $size; $i = 0; $name = array( 'byte', 'kB', 'MB', 'GB' ); while ( $file_size > 1000 ) { $i++; $file_size = $file_size / 1024; } return round( $file_size, 2 ) . " " . $name[$i]; } echo formatFileSize( 1024 * 1024 ); //out = 1 MB