You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
936 B
33 lines
936 B
<?php |
|
|
|
/** |
|
* Convert bytes to human readable format |
|
* |
|
* @param integer bytes Size in bytes to convert |
|
* @return string |
|
*/ |
|
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) |
|
{ |
|
$kilobyte = 1024; |
|
$megabyte = $kilobyte * 1024; |
|
$gigabyte = $megabyte * 1024; |
|
$terabyte = $gigabyte * 1024; |
|
|
|
if (($bytes >= 0) && ($bytes < $kilobyte)) { |
|
return $bytes . ' B'; |
|
|
|
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
|
return round($bytes / $kilobyte, $precision) . ' KB'; |
|
|
|
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
|
return round($bytes / $megabyte, $precision) . ' MB'; |
|
|
|
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
|
return round($bytes / $gigabyte, $precision) . ' GB'; |
|
|
|
} elseif ($bytes >= $terabyte) { |
|
return round($bytes / $terabyte, $precision) . ' TB'; |
|
} else { |
|
return $bytes . ' B'; |
|
} |
|
} |