You are here

function advagg_mod_admin_byte2human in Advanced CSS/JS Aggregation 7.2

Converts a number of bytes into human readable format.

Parameters

string $bytes: Number to convert into a more human readable format.

int $precision: Number of decimals to output.

Return value

string Human readable format of the bytes.

1 call to advagg_mod_admin_byte2human()
advagg_mod_admin_settings_form in advagg_mod/advagg_mod.admin.inc
Form builder; Configure advagg settings.

File

advagg_mod/advagg_mod.admin.inc, line 801
Admin page callbacks for the advagg bundler module.

Code

function advagg_mod_admin_byte2human($bytes, $precision = 0) {
  $units = array(
    '',
    'K',
    'M',
    'G',
    'T',
  );
  $bytes = max($bytes, 0);
  $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  $pow = min($pow, count($units) - 1);
  $bytes /= 1 << 10 * $pow;
  $output = ceil(round($bytes, $precision + 2) * 10) / 10;
  return $output . '' . $units[$pow];
}