summaryrefslogtreecommitdiffstats
path: root/lib/private/helper.php
diff options
context:
space:
mode:
authorPellaeon Lin <nfsmwlin@gmail.com>2013-12-08 22:59:46 +0800
committerPellaeon Lin <nfsmwlin@gmail.com>2013-12-08 22:59:46 +0800
commitfc607e6bce76e9e2f6f52421bdddece951f629cd (patch)
treee823cdd256e88b05a551c797e50f74dd32a20c99 /lib/private/helper.php
parent69f2bde324cd491937a90948a23b06a06c2f2400 (diff)
downloadnextcloud-server-fc607e6bce76e9e2f6f52421bdddece951f629cd.tar.gz
nextcloud-server-fc607e6bce76e9e2f6f52421bdddece951f629cd.zip
Separate PHP upload limit and free space
Diffstat (limited to 'lib/private/helper.php')
-rw-r--r--lib/private/helper.php40
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index c82d3bd4ef4..0bef427c6c1 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -828,23 +828,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);
}
}