Ticket #30908: 30908.diff
File 30908.diff, 1.3 KB (added by , 10 years ago) |
---|
-
wp-includes/functions.php
182 182 /** 183 183 * Convert number of bytes largest unit bytes will fit into. 184 184 * 185 * It is easier to read 1 kB than 1024 bytes and 1MB than 1048576 bytes. Converts185 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts 186 186 * number of bytes to human readable number by taking the number of that unit 187 187 * that the bytes will go into it. Supports TB value. 188 188 * … … 200 200 * @return string|false False on failure. Number string on success. 201 201 */ 202 202 function size_format( $bytes, $decimals = 0 ) { 203 203 204 $quant = array( 204 205 // ========================= Origin ==== 205 206 'TB' => 1099511627776, // pow( 1024, 4) … … 206 207 'GB' => 1073741824, // pow( 1024, 3) 207 208 'MB' => 1048576, // pow( 1024, 2) 208 209 'kB' => 1024, // pow( 1024, 1) 209 'B '=> 1, // pow( 1024, 0)210 'B' => 1, // pow( 1024, 0) 210 211 ); 211 foreach ( $quant as $unit => $mag ) 212 if ( doubleval($bytes) >= $mag ) 212 213 foreach ( $quant as $unit => $mag ) { 214 if ( doubleval( $bytes ) >= $mag ) { 213 215 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; 216 } 217 } 214 218 215 219 return false; 216 220 }