summaryrefslogtreecommitdiffstats
path: root/lib/general.lib.php
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-01-26 02:36:58 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-01-26 02:36:58 -0500
commit8a750c3e875d590d351c3042570a134fcdf03e5d (patch)
tree846df051bf732bd588cd1571d1727123493cef5b /lib/general.lib.php
parenta12679b13d8d06c87308b1d26bc23c6b4fa5d92e (diff)
downloadampache-8a750c3e875d590d351c3042570a134fcdf03e5d.tar.gz
ampache-8a750c3e875d590d351c3042570a134fcdf03e5d.tar.bz2
ampache-8a750c3e875d590d351c3042570a134fcdf03e5d.zip
Move [un]format_bytes() from general.lib.php to UI
Diffstat (limited to 'lib/general.lib.php')
-rw-r--r--lib/general.lib.php52
1 files changed, 2 insertions, 50 deletions
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 0fdf84b6..6833b8bf 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -27,8 +27,8 @@
*/
function set_memory_limit($new_limit) {
- $current_limit = unformat_bytes(ini_get('memory_limit'));
- $new_limit = unformat_bytes($new_limit);
+ $current_limit = unUI::format_bytes(ini_get('memory_limit'));
+ $new_limit = unUI::format_bytes($new_limit);
if ($current_limit < $new_limit) {
ini_set (memory_limit, $new_limit);
@@ -117,54 +117,6 @@ function scrub_arg($arg)
}
/**
- * 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;
-}
-
-function unformat_bytes($value) {
- if (preg_match('/^([0-9]+) *([[:alpha:]]+)$/', $value, $matches)) {
- $value = $matches[1];
- $unit = strtolower(substr($matches[2], 0, 1));
- }
- else {
- return $value;
- }
-
- switch($unit) {
- case 'p':
- $value *= 1024;
- case 't':
- $value *= 1024;
- case 'g':
- $value *= 1024;
- case 'm':
- $value *= 1024;
- case 'k':
- $value *= 1024;
- }
-
- return $value;
-}
-
-/**
* 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.