gde_format_bytes

The Google Doc Embedder gde format bytes function.

Description

gde_format_bytes( $bytes, (int) $precision = 2 ); 

Parameters (2)

0. $bytes
The bytes.
1. $precision — Optional. (int) => 2
The precision.

Usage

  1. if ( !function_exists( 'gde_format_bytes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; 
  3.  
  4. // The bytes. 
  5. $bytes = null; 
  6.  
  7. // The precision. 
  8. $precision = 2; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = gde_format_bytes($bytes, $precision); 
  12.  

Defined (1)

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

/functions.php  
  1. function gde_format_bytes( $bytes, $precision = 2 ) { 
  2. if ( ! is_numeric( $bytes ) || $bytes < 1 ) { 
  3. return __('Unknown', 'google-document-embedder'); 
  4. } else { 
  5. $units = array( 'B', 'KB', __('MB', 'google-document-embedder'), 'GB', 'TB' ); 
  6.  
  7. $bytes = max( $bytes, 0 ); 
  8. $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) ); 
  9. $pow = min( $pow, count( $units ) - 1 ); 
  10.  
  11. $bytes /= pow( 1024, $pow ); 
  12.  
  13. if ( $units[$pow] == "KB" ) { 
  14. // less precision for small file sizes 
  15. return round( $bytes ) . "KB"; 
  16. } else { 
  17. return round( $bytes, $precision ) . $units[$pow];