This is the web log of Tim Bennett, web designer. He also runs Texelate, offering the best web design Leeds, Yorkshire has to offer

Format file size

Sunday, May 14th, 2006 at 8:48 am

Convert the size in bytes for a file into a more user-friendly format

<?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”;

        

        }

    

    }

    

?>

Leave a Reply

You must be logged in to post a comment. If you don't have an account register one now.

Do you need a website or web-related service?
I run an award-winning web design studio.