public static function sizeFormat($bytes, $decimals = 0)
    {
        $quant = array(
            // ========================= Origin ====
            'TB' => 1099511627776,  // pow( 1024, 4)
            'GB' => 1073741824,     // pow( 1024, 3)
            'MB' => 1048576,        // pow( 1024, 2)
            'kB' => 1024,           // pow( 1024, 1)
            'B ' => 1,              // pow( 1024, 0)
        );

        foreach ($quant as $unit => $mag) {
            if (doubleval($bytes) >= $mag) {
                return number_format($bytes / $mag, $decimals).' '.$unit;
            }
        }

        return false;
    }
public static function sizeFormat($bytes, $decimals = 0)
    {
        $quant = array(
            // ========================= Origin ====
            'TB' => 1099511627776,  // pow( 1024, 4)
            'GB' => 1073741824,     // pow( 1024, 3)
            'MB' => 1048576,        // pow( 1024, 2)
            'kB' => 1024,           // pow( 1024, 1)
            'B ' => 1,              // pow( 1024, 0)
        );

        foreach ($quant as $unit => $mag) {
            if (doubleval($bytes) >= $mag) {
                return number_format($bytes / $mag, $decimals).' '.$unit;
            }
        }

        return false;
    }
public static function sizeFormat ( $ bytes , $ decimals = 0 ) { $ quant = array ( // ========================= Origin ==== 'TB' => 1099511627776 , // pow( 1024, 4) 'GB' => 1073741824 , // pow( 1024, 3) 'MB' => 1048576 , // pow( 1024, 2) 'kB' => 1024 , // pow( 1024, 1) 'B ' => 1 , // pow( 1024, 0) ) ; foreach ( $ quant as $ unit => $ mag ) { if ( doubleval ( $ bytes ) >= $ mag ) { return number_format ( $ bytes / $ mag , $ decimals ) . ' ' . $ unit ; } } return false ; }
Converts number of bytes to human readable number by taking the number of that unit
that the bytes will go into it. Supports TB value.

Please note that integers in PHP are limited to 32 bits, unless they are on
64 bit architecture, then they have 64 bit size. If you need to place the
larger size then what PHP integer type will hold, then use a string. It will
be converted to a double, which should always have 64 bit length.

Credit: http://core.svn.wordpress.org/trunk/wp-includes/functions.php

@param int $bytes    Bytes
@param int $decimals Decimals

@return  bool|string
Converts number of bytes to human readable number by taking the number of that unit that the bytes will go into it . Supports TB value .