summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files.php4
-rw-r--r--lib/private/helper.php26
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/private/files.php b/lib/private/files.php
index 152595ba697..3affcf10449 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -279,9 +279,7 @@ class OC_Files {
return false;
$size -= 1;
} else {
- $size = OC_Helper::humanFileSize($size);
- $size = substr($size, 0, -1); //strip the B
- $size = str_replace(' ', '', $size); //remove the space between the size and the postfix
+ $size = OC_Helper::phpFileSize($size);
}
//don't allow user to break his config -- broken or malicious size input
diff --git a/lib/private/helper.php b/lib/private/helper.php
index ab1e0d38924..4058ec199a7 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -306,6 +306,32 @@ class OC_Helper {
}
/**
+ * @brief Make a php file size
+ * @param int $bytes file size in bytes
+ * @return string a php parseable file size
+ *
+ * Makes 2048 to 2k and 2^41 to 2048G
+ */
+ public static function phpFileSize($bytes) {
+ if ($bytes < 0) {
+ return "?";
+ }
+ if ($bytes < 1024) {
+ return $bytes . "B";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return $bytes . "K";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return $bytes . "M";
+ }
+ $bytes = round($bytes / 1024, 1);
+ return $bytes . "G";
+ }
+
+ /**
* @brief Make a computer file size
* @param string $str file size in human readable format
* @return int a file size in bytes