Convert Filesize to Highest Extension

A quick and easy way to display an easy to read size, useful if you have any type of image or general file uploading capability in your web apps. Showing users that 4404019 bytes too large is much less helpful than saying 4.2mb
function convert_filesize ( $filesize ) { 
    if ( is_numeric($filesize) )
        $increment = 1024; 
        $level = 0; 
        $postfix = array('Byte','KB','MB','GB','TB','PB'); 
        while ( ($filesize / $increment) > 0.9 )
            $filesize = $filesize / $decr; $step++;
        return round($filesize, 2) .' '. $postfix[ $level ]; 
        return 'Error: Filesize must be a number.'; 
Small dog web development studio

View All Our Posts

Web application developers in western Washington, creating user centric web solutions for businesses of all shapes and sizes.

Our projects include ecommerce, event organization, user driven web applications and more.

Small Dog Studios, LLC. Small Dog Studios News