Make WordPress Core


Ignore:
Timestamp:
07/15/2007 05:52:50 PM (18 years ago)
Author:
ryan
Message:

Show upload file size in upload browser. Props tellyworth. fixes #4561

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r5796 r5801  
    9090
    9191    return number_format($number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
     92}
     93
     94function size_format($bytes, $decimals = null) {
     95    // technically the correct unit names for powers of 1024 are KiB, MiB etc
     96    // see http://en.wikipedia.org/wiki/Byte
     97    $quant = array(
     98        'TB' => pow(1024, 4),
     99        'GB' => pow(1024, 3),
     100        'MB' => pow(1024, 2),
     101        'kB' => pow(1024, 1),
     102        'B'  => pow(1024, 0),
     103    );
     104
     105    foreach ($quant as $unit => $mag)
     106        if ( intval($bytes) >= $mag )
     107            return number_format_i18n($bytes / $mag, $decimals) . ' ' . $unit;
    92108}
    93109
Note: See TracChangeset for help on using the changeset viewer.