Adapted system feedback when uploading too large documents

. Added clientside check to avoid uploads > max upload size on serverside
. Adapted message returned by server, when max upload size is exceeded
This commit is contained in:
Cris
2022-02-23 12:30:08 +01:00
parent 78d863a383
commit c8f93cae07
4 changed files with 66 additions and 3 deletions
@@ -119,7 +119,7 @@ class requestAnrechnung extends Auth_Controller
// Validate data
if (empty($_FILES['uploadfile']['name']))
{
return $this->outputJsonError($this->p->t('ui', 'errorUploadFehlt'));
return $this->outputJsonError($this->p->t('ui', 'errorUploadFehltOderZuGross'));
}
if (isEmptyString($begruendung_id) ||
@@ -26,7 +26,8 @@ $this->load->view(
'neu',
'maxZeichen',
'errorBestaetigungFehlt',
'systemfehler'
'systemfehler',
'errorDokumentZuGross'
),
'anrechnung' => array(
'deadlineUeberschritten',
@@ -179,7 +180,7 @@ $this->load->view(
<div class="form-inline panel-body">
<div class="form-group">
<input type="file" id="requestAnrechnung-uploadfile"
name="uploadfile" accept=".pdf" size="50"
name="uploadfile" accept=".pdf" size="50" data-maxsize="<?php echo (int)ini_get('upload_max_filesize') * 1024 ?>"
required>
</div>
<span id="requestAnrechnung-uploadTooltip" data-toggle="tooltip" data-placement="right"
@@ -3,6 +3,8 @@ const ANRECHNUNGSTATUS_REJECTED = 'rejected';
const HERKUNFT_DER_KENNTNISSE_MAX_LENGTH = 125;
$(function(){
const uploadMaxFilesize = $('#requestAnrechnung-uploadfile').data('maxsize') ; // in byte
// Set status alert color
requestAnrechnung.setStatusAlertColor();
@@ -26,6 +28,12 @@ $(function(){
// Avoid form redirecting automatically
e.preventDefault();
var fileInput = $('#requestAnrechnung-uploadfile');
if (!requestAnrechnung.fileSizeOk(fileInput, uploadMaxFilesize)) // in byte
{
return FHC_DialogLib.alertWarning(FHC_PhrasesLib.t("ui", "errorDokumentZuGross"));
}
FHC_AjaxClient.ajaxCallPost(
FHC_JS_DATA_STORAGE_OBJECT.called_path + "/apply",
{
@@ -161,5 +169,19 @@ var requestAnrechnung = {
// Disable all form elements
$("#requestAnrechnung-form :input").prop("disabled", true);
},
fileSizeOk: function(fileInput, maxSize){
if (fileInput.get(0).files.length){
var fileSize = fileInput.get(0).files[0].size; // in bytes
if (fileSize > maxSize)
{
return false;
}
return true;
}
}
}
+40
View File
@@ -12333,6 +12333,46 @@ array(
)
)
),
array(
'app' => 'core',
'category' => 'ui',
'phrase' => 'errorDokumentZuGross',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => "Dokument zu groß",
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => "Document maximum size exceeded",
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'ui',
'phrase' => 'errorUploadFehltOderZuGross',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => "Dokument fehlt oder zu groß",
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => "Document missing or maximum size exceeded",
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'ui',