[Pkg-owncloud-commits] [owncloud] 01/85: Fix setting the max-upload-size for really large values.
David Prévot
taffit at moszumanska.debian.org
Tue Jun 17 19:12:39 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch 6.0
in repository owncloud.
commit 6f8a24c2cdd68f35693a9bf10f25982ac61949f6
Author: Fabian Henze <flyser42 at gmx.de>
Date: Thu Apr 3 01:17:28 2014 +0200
Fix setting the max-upload-size for really large values.
php can only parse filesize units up to gigabytes, not terabytes or petabytes.
---
lib/private/files.php | 4 +---
lib/private/helper.php | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/lib/private/files.php b/lib/private/files.php
index 0ec051c..4fd55cc 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -277,9 +277,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 5182f57..1cc6413 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -274,6 +274,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 a fancy format
* @return int a file size in bytes
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list