summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <hey@jancborchardt.net>2014-02-04 08:04:19 -0800
committerJan-Christoph Borchardt <hey@jancborchardt.net>2014-02-04 08:04:19 -0800
commit0609f30d1c4ab01804d0ecf943c0d9146bb41cb7 (patch)
tree28f39a748ad378c20fbc12e7398d0df932441d31 /lib
parentbd6734291cd56b4d3d494a6e4138435ecb49171e (diff)
parent099b71c712c38de7dac7e386252da02bb0cadf12 (diff)
downloadnextcloud-server-0609f30d1c4ab01804d0ecf943c0d9146bb41cb7.tar.gz
nextcloud-server-0609f30d1c4ab01804d0ecf943c0d9146bb41cb7.zip
Merge pull request #6235 from NCTU-NBA/pr-exceed_upload_limit_msg
Change misleading message when file size exceeds upload limit
Diffstat (limited to 'lib')
-rw-r--r--lib/private/helper.php40
-rw-r--r--lib/public/util.php19
2 files changed, 47 insertions, 12 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index ce5708e2bb9..580f81acc62 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -808,23 +808,39 @@ class OC_Helper {
* @return number of bytes representing
*/
public static function maxUploadFilesize($dir) {
- $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
- $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
- $freeSpace = \OC\Files\Filesystem::free_space($dir);
- if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
- $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED;
- } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
- $maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts
- } else {
- $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
- }
+ return min(self::freeSpace($dir), self::uploadLimit());
+ }
+ /**
+ * Calculate free space left within user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function freeSpace($dir) {
+ $freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($freeSpace !== \OC\Files\SPACE_UNKNOWN) {
$freeSpace = max($freeSpace, 0);
+ return $freeSpace;
+ } else {
+ return INF;
+ }
+ }
- return min($maxUploadFilesize, $freeSpace);
+ /**
+ * Calculate PHP upload limit
+ *
+ * @return PHP upload file size limit
+ */
+ public static function uploadLimit() {
+ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
+ $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
+ if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
+ return INF;
+ } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
+ return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
- return $maxUploadFilesize;
+ return min($upload_max_filesize, $post_max_size);
}
}
diff --git a/lib/public/util.php b/lib/public/util.php
index 26c5a15cff2..d8497e29cfc 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -466,4 +466,23 @@ class Util {
public static function maxUploadFilesize($dir) {
return \OC_Helper::maxUploadFilesize($dir);
}
+
+ /**
+ * Calculate free space left within user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function freeSpace($dir) {
+ return \OC_Helper::freeSpace($dir);
+ }
+
+ /**
+ * Calculate PHP upload limit
+ *
+ * @return number of bytes representing
+ */
+ public static function uploadLimit() {
+ return \OC_Helper::uploadLimit();
+ }
}