size_format [ WordPress Function ]
| Parameters: |
|
| Links: | |
| Returns: |
|
| Defined at: |
|
Convert number of bytes largest unit bytes will fit into.
It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. 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.
Technically the correct unit names for powers of 1024 are KiB, MiB etc.
Source
<?php
function size_format( $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_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
return false;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- #19067 (Duplicate functionality in core: size_format() and ...
size_format() - /wp-includes/functions.php wp_convert_bytes_to_hr() ... is only used once in core and where it is used could be replaced with size_format().
core.trac.wordpress.org - Properly Format your Filesize in WordPress - Better WordPress
Mar 6, 2011 ... Format the sizes of your attachments (or any other files) nicely using size_format( ).
betterwp.net - Oracle DBA Queries - Database status, uptime, how big is it, etc...
col "Database Size" format a20 col "Free space" format a20 col "Used space" format a20 select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database ...
www.shutdownabort.com - address / size format (idb mode only)
start_address. The start address for the range of memory. end_address. The end address for the range of memory. size. The number of memory values of the ...
software.intel.com