Title: wp_convert_hr_to_bytes
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_convert_hr_to_bytes( string $value ): int

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#wp--skip-link--target)

Converts a shorthand byte value to an integer byte value.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#parameters)󠁿

 `$value`stringrequired

A (PHP ini) byte value, either shorthand or ordinary.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#return)󠁿

 int An integer byte value.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#source)󠁿

    ```php
    function wp_convert_hr_to_bytes( $value ) {
    	$value = strtolower( trim( $value ) );
    	$bytes = (int) $value;

    	if ( str_contains( $value, 'g' ) ) {
    		$bytes *= GB_IN_BYTES;
    	} elseif ( str_contains( $value, 'm' ) ) {
    		$bytes *= MB_IN_BYTES;
    	} elseif ( str_contains( $value, 'k' ) ) {
    		$bytes *= KB_IN_BYTES;
    	}

    	// Deal with large (float) values which run into the maximum integer size.
    	return min( $bytes, PHP_INT_MAX );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/load.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/load.php#L1687)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/load.php#L1687-L1701)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Debug_Data::get_wp_media()](https://developer.wordpress.org/reference/classes/wp_debug_data/get_wp_media/)`wp-admin/includes/class-wp-debug-data.php` |

Gets the WordPress media section of the debug data.

  | 
| [WP_Site_Health::get_test_file_uploads()](https://developer.wordpress.org/reference/classes/wp_site_health/get_test_file_uploads/)`wp-admin/includes/class-wp-site-health.php` |

Tests if ‘file_uploads’ directive in PHP.ini is turned off.

  | 
| [wp_raise_memory_limit()](https://developer.wordpress.org/reference/functions/wp_raise_memory_limit/)`wp-includes/functions.php` |

Attempts to raise the PHP memory limit for memory intensive processes.

  | 
| [wp_initial_constants()](https://developer.wordpress.org/reference/functions/wp_initial_constants/)`wp-includes/default-constants.php` |

Defines initial WordPress constants.

  | 
| [wp_max_upload_size()](https://developer.wordpress.org/reference/functions/wp_max_upload_size/)`wp-includes/media.php` |

Determines the maximum upload size allowed in php.ini.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Moved from media.php to load.php. | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/?output_format=md#comment-content-6914)
 2.   [wbeaumo](https://profiles.wordpress.org/wbeaumo/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_convert_hr_to_bytes/#comment-6914)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_convert_hr_to_bytes%2F%23comment-6914)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_convert_hr_to_bytes%2F%23comment-6914)
 4. Use [size_format()](https://developer.wordpress.org/reference/functions/size_format/)
    to do the opposite (i.e., convert bytes to human-readable format).
 5. `<?php
     $hr_bytes = size_format( 1024 ); // Returns '1 KiB'
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_convert_hr_to_bytes%2F%3Freplytocom%3D6914%23feedback-editor-6914)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_convert_hr_to_bytes%2F)
before being able to contribute a note or feedback.