Make WordPress Core

Ticket #30908: 30908.diff

File 30908.diff, 1.3 KB (added by tillkruess, 10 years ago)
  • wp-includes/functions.php

     
    182182/**
    183183 * Convert number of bytes largest unit bytes will fit into.
    184184 *
    185  * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts
     185 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts
    186186 * number of bytes to human readable number by taking the number of that unit
    187187 * that the bytes will go into it. Supports TB value.
    188188 *
     
    200200 * @return string|false False on failure. Number string on success.
    201201 */
    202202function size_format( $bytes, $decimals = 0 ) {
     203
    203204        $quant = array(
    204205                // ========================= Origin ====
    205206                'TB' => 1099511627776,  // pow( 1024, 4)
     
    206207                'GB' => 1073741824,     // pow( 1024, 3)
    207208                'MB' => 1048576,        // pow( 1024, 2)
    208209                'kB' => 1024,           // pow( 1024, 1)
    209                 'B ' => 1,              // pow( 1024, 0)
     210                'B' => 1,              // pow( 1024, 0)
    210211        );
    211         foreach ( $quant as $unit => $mag )
    212                 if ( doubleval($bytes) >= $mag )
     212
     213        foreach ( $quant as $unit => $mag ) {
     214                if ( doubleval( $bytes ) >= $mag ) {
    213215                        return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
     216                }
     217        }
    214218
    215219        return false;
    216220}