From 69f2bde324cd491937a90948a23b06a06c2f2400 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sun, 8 Dec 2013 15:41:20 +0800 Subject: [PATCH 01/12] Change misleading message when file size exceeds upload limit --- apps/files/js/file-upload.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index e9663353f74..979bb74b13f 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -235,8 +235,8 @@ $(document).ready(function() { //check max upload size if (selection.totalBytes > $('#max_upload').val()) { - data.textStatus = 'notenoughspace'; - data.errorThrown = t('files', 'Not enough space available'); + data.textStatus = 'sizeexceedlimit'; + data.errorThrown = t('files', 'File size exceeds upload limit'); } // end upload for whole selection on error From fc607e6bce76e9e2f6f52421bdddece951f629cd Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sun, 8 Dec 2013 22:59:46 +0800 Subject: [PATCH 02/12] Separate PHP upload limit and free space --- lib/private/helper.php | 42 +++++++++++++++++++++++++++++------------- lib/public/util.php | 19 +++++++++++++++++++ 2 files changed, 48 insertions(+), 13 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 min($maxUploadFilesize, $freeSpace); + return $freeSpace; } else { - return $maxUploadFilesize; + return INF; + } + } + + /** + * 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 min($upload_max_filesize, $post_max_size); } } diff --git a/lib/public/util.php b/lib/public/util.php index 1d76fd1e1f7..cf7ac63ba51 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -458,4 +458,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(); + } } From 64bf0fa47fe4c623672cf86e831f66974e7f650c Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sun, 8 Dec 2013 23:17:35 +0800 Subject: [PATCH 03/12] Display different messages for uploadLimit and freeSpace --- apps/files/index.php | 4 ++++ apps/files/js/file-upload.js | 10 ++++++++-- apps/files/templates/index.php | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index 8f6838aa0d9..4ea0f9f2496 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -103,6 +103,8 @@ if ($needUpgrade) { } else { // information about storage capacities $storageInfo=OC_Helper::getStorageInfo($dir); + $freeSpace=OCP\Util::freeSpace($dir); + $uploadLimit=OCP\Util::uploadLimit(); $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir); $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code) @@ -136,6 +138,8 @@ if ($needUpgrade) { $tmpl->assign('trashEmpty', $trashEmpty); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); + $tmpl->assign('freeSpace', $freeSpace); + $tmpl->assign('uploadLimit', $uploadLimit); $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']); $tmpl->assign('isPublic', false); diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 979bb74b13f..7bd0eb81f57 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -233,11 +233,17 @@ $(document).ready(function() { // add size selection.totalBytes += file.size; - //check max upload size - if (selection.totalBytes > $('#max_upload').val()) { + // check PHP upload limit + if (selection.totalBytes > $('#upload_limit').val()) { data.textStatus = 'sizeexceedlimit'; data.errorThrown = t('files', 'File size exceeds upload limit'); } + + // check free space + if (selection.totalBytes > $('#free_space').val()) { + data.textStatus = 'notenoughspace'; + data.errorThrown = t('files', 'Not enough free space'); + } // end upload for whole selection on error if (data.errorThrown) { diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 00ec109621f..3d8a7f78e41 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -15,9 +15,10 @@
= 0):?> - + + + From 0aa38165a4659fedd98f752bdd99bf174ed98a76 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Wed, 11 Dec 2013 12:17:28 +0800 Subject: [PATCH 04/12] Update #free_space on getstoragestats AJAX call --- apps/files/js/files.js | 1 + apps/files/lib/helper.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index fdaa3aa3342..0a2f1aef013 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -41,6 +41,7 @@ Files={ } if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { $('#max_upload').val(response.data.uploadMaxFilesize); + $('#free_space').val(response.data.freeSpace); $('#upload.button').attr('original-title', response.data.maxHumanFilesize); $('#usedSpacePercent').val(response.data.usedSpacePercent); Files.displayStorageWarnings(); diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index eaff28178ea..2f4a9790662 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -6,6 +6,7 @@ class Helper { public static function buildFileStorageStatistics($dir) { $l = new \OC_L10N('files'); + $freeSpace=OCP\Util::freeSpace($dir); $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; @@ -15,6 +16,7 @@ class Helper return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, + 'freeSpace' => $freeSpace, 'usedSpacePercent' => (int)$storageInfo['relative']); } From 4b081be9569ed831c8f0fb7448bf798f004b8816 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Wed, 11 Dec 2013 12:09:48 +0800 Subject: [PATCH 05/12] #max_upload is needed after all --- apps/files/templates/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 3d8a7f78e41..f20a3f1d073 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -15,7 +15,7 @@
= 0):?> - + From 5ddd85ff9cb64c10974804e810f8f68f275114a3 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Wed, 11 Dec 2013 15:40:58 +0800 Subject: [PATCH 06/12] Contextual upload error message --- apps/files/js/file-upload.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 7bd0eb81f57..1a36a580532 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -236,13 +236,13 @@ $(document).ready(function() { // check PHP upload limit if (selection.totalBytes > $('#upload_limit').val()) { data.textStatus = 'sizeexceedlimit'; - data.errorThrown = t('files', 'File size exceeds upload limit'); + data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}').replace('{size1}', humanFileSize(selection.totalBytes)).replace('{size2}', humanFileSize($('#upload_limit').val())); } // check free space if (selection.totalBytes > $('#free_space').val()) { data.textStatus = 'notenoughspace'; - data.errorThrown = t('files', 'Not enough free space'); + data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left').replace('{size1}', humanFileSize(selection.totalBytes)).replace('{size2}', humanFileSize($('#free_space').val())); } // end upload for whole selection on error From dbbbfee7deb4778e4a6c0a96a50d022a414584ae Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Wed, 15 Jan 2014 12:36:27 +0800 Subject: [PATCH 07/12] Fix namespace --- apps/files/lib/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index 2f4a9790662..e2f545e9e3f 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -6,7 +6,7 @@ class Helper { public static function buildFileStorageStatistics($dir) { $l = new \OC_L10N('files'); - $freeSpace=OCP\Util::freeSpace($dir); + $freeSpace=\OCP\Util::freeSpace($dir); $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; From cd6ab2931325323cb59961c4327a18d934ecc72a Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Thu, 16 Jan 2014 17:51:00 +0800 Subject: [PATCH 08/12] Use t() 's native method --- apps/files/js/file-upload.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 1a36a580532..a003e5eec86 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -236,13 +236,19 @@ $(document).ready(function() { // check PHP upload limit if (selection.totalBytes > $('#upload_limit').val()) { data.textStatus = 'sizeexceedlimit'; - data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}').replace('{size1}', humanFileSize(selection.totalBytes)).replace('{size2}', humanFileSize($('#upload_limit').val())); + data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}', { + 'size1': humanFileSize(selection.totalBytes), + 'size2': humanFileSize($('#upload_limit').val()) + }); } // check free space if (selection.totalBytes > $('#free_space').val()) { data.textStatus = 'notenoughspace'; - data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left').replace('{size1}', humanFileSize(selection.totalBytes)).replace('{size2}', humanFileSize($('#free_space').val())); + data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left', { + '{size1}': humanFileSize(selection.totalBytes), + '{size2}': humanFileSize($('#free_space').val()) + }); } // end upload for whole selection on error From 6ec50e4b0c435789732186eb3c6839883061e5a8 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Thu, 16 Jan 2014 19:48:46 +0800 Subject: [PATCH 09/12] Comments to clarify --- apps/files/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index 4ea0f9f2496..c8b04bd4627 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -136,10 +136,10 @@ if ($needUpgrade) { $tmpl->assign('files', $files); $tmpl->assign('trash', $trashEnabled); $tmpl->assign('trashEmpty', $trashEmpty); - $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); + $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('freeSpace', $freeSpace); - $tmpl->assign('uploadLimit', $uploadLimit); + $tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']); $tmpl->assign('isPublic', false); From 4726a2021b70f2ee70b4cb8817fd89a8532b848b Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Fri, 17 Jan 2014 17:10:42 +0800 Subject: [PATCH 10/12] Add $freeSpace and $uploadLimit to files_sharing --- apps/files_sharing/public.php | 4 ++++ apps/files_sharing/templates/public.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index f4042f65248..540f2b004c6 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -141,6 +141,8 @@ if (isset($path)) { OCP\Util::addScript('files', 'jquery.iframe-transport'); OCP\Util::addScript('files', 'jquery.fileupload'); $maxUploadFilesize=OCP\Util::maxUploadFilesize($path); + $freeSpace=OCP\Util::freeSpace($dir); + $uploadLimit=OCP\Util::uploadLimit(); $tmpl = new OCP\Template('files_sharing', 'public', 'base'); $tmpl->assign('uidOwner', $shareOwner); $tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner)); @@ -161,6 +163,8 @@ if (isset($path)) { $tmpl->assign('allowPublicUploadEnabled', $allowPublicUploadEnabled); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); + $tmpl->assign('freeSpace', $freeSpace); + $tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit $urlLinkIdentifiers= (isset($token)?'&t='.$token:'') .(isset($_GET['dir'])?'&dir='.$_GET['dir']:'') diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 1d527dca8eb..124b4a1ae9f 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -34,6 +34,8 @@ + + From 19675c2c9de3580c32ee24b22b8ded11dc110b1c Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Fri, 24 Jan 2014 22:54:16 +0800 Subject: [PATCH 11/12] Fix variable name --- apps/files/js/file-upload.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index a003e5eec86..0d7df31f355 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -246,8 +246,8 @@ $(document).ready(function() { if (selection.totalBytes > $('#free_space').val()) { data.textStatus = 'notenoughspace'; data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left', { - '{size1}': humanFileSize(selection.totalBytes), - '{size2}': humanFileSize($('#free_space').val()) + 'size1': humanFileSize(selection.totalBytes), + 'size2': humanFileSize($('#free_space').val()) }); } From 929c930b0afd682bb98eb389d7ebad91bb34d643 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Wed, 29 Jan 2014 21:24:31 +0800 Subject: [PATCH 12/12] Use $storageInfo['free'] --- apps/files/index.php | 2 +- apps/files/lib/helper.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index c8b04bd4627..61b32bc6fe3 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -103,7 +103,7 @@ if ($needUpgrade) { } else { // information about storage capacities $storageInfo=OC_Helper::getStorageInfo($dir); - $freeSpace=OCP\Util::freeSpace($dir); + $freeSpace=$storageInfo['free']; $uploadLimit=OCP\Util::uploadLimit(); $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir); $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index e2f545e9e3f..21d1f50e587 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -6,7 +6,6 @@ class Helper { public static function buildFileStorageStatistics($dir) { $l = new \OC_L10N('files'); - $freeSpace=\OCP\Util::freeSpace($dir); $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; @@ -16,7 +15,7 @@ class Helper return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, - 'freeSpace' => $freeSpace, + 'freeSpace' => $storageInfo['free'], 'usedSpacePercent' => (int)$storageInfo['relative']); }