Merge pull request #6235 from NCTU-NBA/pr-exceed_upload_limit_msg
Change misleading message when file size exceeds upload limit
This commit is contained in:
commit
0609f30d1c
8 changed files with 77 additions and 19 deletions
|
@ -101,6 +101,8 @@ if ($needUpgrade) {
|
|||
} else {
|
||||
// information about storage capacities
|
||||
$storageInfo=OC_Helper::getStorageInfo($dir);
|
||||
$freeSpace=$storageInfo['free'];
|
||||
$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)
|
||||
|
@ -132,8 +134,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); // PHP upload limit
|
||||
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
|
||||
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
|
||||
$tmpl->assign('isPublic', false);
|
||||
|
|
|
@ -241,10 +241,22 @@ $(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', '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 space available');
|
||||
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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -15,6 +15,7 @@ class Helper
|
|||
|
||||
return array('uploadMaxFilesize' => $maxUploadFilesize,
|
||||
'maxHumanFilesize' => $maxHumanFilesize,
|
||||
'freeSpace' => $storageInfo['free'],
|
||||
'usedSpacePercent' => (int)$storageInfo['relative']);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
<div id="upload" class="button"
|
||||
title="<?php p($l->t('Upload') . ' max. '.$_['uploadMaxHumanFilesize']) ?>">
|
||||
<?php if($_['uploadMaxFilesize'] >= 0):?>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" id="max_upload"
|
||||
value="<?php p($_['uploadMaxFilesize']) ?>">
|
||||
<input type="hidden" id="max_upload" name="MAX_FILE_SIZE" value="<?php p($_['uploadMaxFilesize']) ?>">
|
||||
<?php endif;?>
|
||||
<input type="hidden" id="upload_limit" value="<?php p($_['uploadLimit']) ?>">
|
||||
<input type="hidden" id="free_space" value="<?php p($_['freeSpace']) ?>">
|
||||
<?php if(isset($_['dirToken'])):?>
|
||||
<input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
|
||||
<input type="hidden" id="dirToken" name="dirToken" value="<?php p($_['dirToken']) ?>" />
|
||||
|
|
|
@ -143,6 +143,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));
|
||||
|
@ -162,6 +164,8 @@ if (isset($path)) {
|
|||
}
|
||||
$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']:'')
|
||||
|
|
|
@ -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 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue