diff options
author | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-10-15 19:16:42 +0000 |
---|---|---|
committer | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-10-15 19:16:42 +0000 |
commit | 63031fb6c1b3dc31d2d9cc1d0e7148c827656922 (patch) | |
tree | 5c3b60b2cffaff77b64461155fcaab9c345f4d1d /lib/general.lib.php | |
parent | 680e9f6206de1e17cdc63ebec498f6ebafa667b6 (diff) | |
download | ampache-63031fb6c1b3dc31d2d9cc1d0e7148c827656922.tar.gz ampache-63031fb6c1b3dc31d2d9cc1d0e7148c827656922.tar.bz2 ampache-63031fb6c1b3dc31d2d9cc1d0e7148c827656922.zip |
Use a function to format bytes -> human-readable sizes. Also bump catalog build
memory profiling logging to level 5; fixes FS#141.
Diffstat (limited to 'lib/general.lib.php')
-rw-r--r-- | lib/general.lib.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/general.lib.php b/lib/general.lib.php index 8033c927..c941bae9 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -111,6 +111,29 @@ function unhtmlentities($string) { } //unhtmlentities /** + * format_bytes + * Turns a size in bytes into a human-readable value + */ +function format_bytes($value, $precision = 2) { + $divided = 0; + while (strlen(floor($value)) > 3) { + $value = ($value / 1024); + $divided++; + } + + switch ($divided) { + case 1: $unit = 'kB'; break; + case 2: $unit = 'MB'; break; + case 3: $unit = 'GB'; break; + case 4: $unit = 'TB'; break; + case 5: $unit = 'PB'; break; + default: $unit = 'B'; break; + } // end switch + + return round($value, $precision) . ' ' . $unit; +} + +/** * make_bool * This takes a value and returns what we consider to be the correct boolean * value. We need a special function because PHP considers "false" to be true. |