size_format( int|string $bytes, int $decimals ): string|false  Converts a number of bytes to the largest unit the bytes will fit into.   Description It is easier to read 1 KB than 1024 bytes and 1 MB 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 YB 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.   Parameters   $bytes int|string Required    Number of bytes. Note max integer size for integers.    $decimals int Optional     Precision of number of decimal places. Default 0.      Return string|false Number string on success, false on failure.   More Information Usage: // Returns the string '1 KiB'
<?php $size_to_display = size_format(1024); ?>   Source  File: wp-includes/functions.php. View all references  function size_format( $bytes, $decimals = 0 ) {
	$quant = array(
		/* translators: Unit symbol for yottabyte. */
		_x( 'YB', 'unit symbol' ) => YB_IN_BYTES,
		/* translators: Unit symbol for zettabyte. */
		_x( 'ZB', 'unit symbol' ) => ZB_IN_BYTES,
		/* translators: Unit symbol for exabyte. */
		_x( 'EB', 'unit symbol' ) => EB_IN_BYTES,
		/* translators: Unit symbol for petabyte. */
		_x( 'PB', 'unit symbol' ) => PB_IN_BYTES,
		/* translators: Unit symbol for terabyte. */
		_x( 'TB', 'unit symbol' ) => TB_IN_BYTES,
		/* translators: Unit symbol for gigabyte. */
		_x( 'GB', 'unit symbol' ) => GB_IN_BYTES,
		/* translators: Unit symbol for megabyte. */
		_x( 'MB', 'unit symbol' ) => MB_IN_BYTES,
		/* translators: Unit symbol for kilobyte. */
		_x( 'KB', 'unit symbol' ) => KB_IN_BYTES,
		/* translators: Unit symbol for byte. */
		_x( 'B', 'unit symbol' )  => 1,
	);

	if ( 0 === $bytes ) {
		/* translators: Unit symbol for byte. */
		return number_format_i18n( 0, $decimals ) . ' ' . _x( 'B', 'unit symbol' );
	}

	foreach ( $quant as $unit => $mag ) {
		if ( (float) $bytes >= $mag ) {
			return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
		}
	}

	return false;
}
   Related  Uses    Uses Description      _x() wp-includes/l10n.php   Retrieves translated string with gettext context.     number_format_i18n() wp-includes/functions.php   Converts float number to format based on the locale.   
   Used By    Used By Description      WP_Debug_Dat8b7c:f320:99b9:690f:4595:cd17:293a:c069get_sizes() wp-admin/includes/class-wp-debug-data.php   Fetches the sizes of the WordPress directories: wordpress (ABSPATH), plugins, themes, and uploads.     WP_Debug_Dat8b7c:f320:99b9:690f:4595:cd17:293a:c069debug_data() wp-admin/includes/class-wp-debug-data.php   Static function for generating site debug data when required.     upload_is_user_over_quota() wp-admin/includes/ms.php   Check whether a site has used its allotted upload space.     display_space_usage() wp-admin/includes/ms.php   Displays the amount of disk space used by the current site. Not used in core.     wp_import_upload_form() wp-admin/includes/template.php   Outputs the form used by the importers to accept the data to be imported.     multisite_over_quota_message() wp-admin/includes/media.php   Displays the out of storage quota message in Multisite.     attachment_submitbox_metadata() wp-admin/includes/media.php   Displays non-editable attachment metadata in the publish meta box.     media_upload_form() wp-admin/includes/media.php   Outputs the legacy media upload form.     wpmu_checkAvailableSpace() wp-admin/includes/ms-deprecated.php   Determines if the available space defined by the admin has been exceeded by the user.     wp_prepare_attachment_for_js() wp-includes/media.php   Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.     wp_xmlrpc_server8b7c:f320:99b9:690f:4595:cd17:293a:c069mw_newMediaObject() wp-includes/class-wp-xmlrpc-server.php   Uploads a file, following your settings.     wp_print_media_templates() wp-includes/media-template.php   Prints the templates used in the media manager.   
    Changelog    Version Description     6.0.0 Support for PB, EB, ZB, and YB was added.   2.3.0 Introduced.    

    
{'path': 'public/docs/wordpress/functions/size_format.html', 'source': 'DevDocs.IO'}