wp_convert_bytes_to_hr

Converts an integer byte value to a shorthand byte value.

Description

(string) wp_convert_bytes_to_hr( (int) $bytes ); 

Returns (string)

A shorthand byte value.

Parameters (1)

0. $bytes (int)
An integer byte value.

Usage

  1. if ( !function_exists( 'wp_convert_bytes_to_hr' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // An integer byte value. 
  5. $bytes = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_convert_bytes_to_hr($bytes); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/deprecated.php  
  1. function wp_convert_bytes_to_hr( $bytes ) { 
  2. _deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' ); 
  3.  
  4. $units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' ); 
  5. $log = log( $bytes, KB_IN_BYTES ); 
  6. $power = (int) $log; 
  7. $size = pow( KB_IN_BYTES, $log - $power ); 
  8.  
  9. if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) { 
  10. $unit = $units[ $power ]; 
  11. } else { 
  12. $size = $bytes; 
  13. $unit = $units[0]; 
  14.  
  15. return $size . $unit;