Ticket #5246: size_format.diff
| File size_format.diff, 1.5 KB (added by , 18 years ago) |
|---|
-
wp-includes/functions.php
89 89 return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); 90 90 } 91 91 92 92 /** 93 * Formats a size with the correct byte suffix. 94 * 95 * @param number $bytes number of bytes to format 96 * @param int $decimals number of digits after the decimal point to be used, optional 97 * @return string|bool formatted number (according to current locale) with the correct suffix (KB, MB, etc.) in the end or false on error 98 */ 93 99 function size_format( $bytes, $decimals = null ) { 100 if (!is_numeric($bytes)) { 101 return false; 102 } 94 103 // technically the correct unit names for powers of 1024 are KiB, MiB etc 95 104 // see http://en.wikipedia.org/wiki/Byte 96 105 $quant = array( … … 98 107 'TB' => 1099511627776, // pow( 1024, 4) 99 108 'GB' => 1073741824, // pow( 1024, 3) 100 109 'MB' => 1048576, // pow( 1024, 2) 101 ' kB' => 1024, // pow( 1024, 1)110 'KB' => 1024, // pow( 1024, 1) 102 111 'B ' => 1, // pow( 1024, 0) 103 112 ); 104 113 105 114 foreach ( $quant as $unit => $mag ) 106 if ( intval( $bytes )>= $mag )115 if ( $bytes >= $mag ) 107 116 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; 117 return false; 108 118 } 109 119 110 120 … … 1484 1494 return abs( intval( $maybeint ) ); 1485 1495 } 1486 1496 1487 ?> 1488 No newline at end of file 1497 ?>