From 571a10751f500553d4b65fda1b8e8fd9bd32283f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 20 Oct 2016 11:29:50 +0200 Subject: [PATCH] Display error when trying to upload more files than specified in max_file_uploads (#5483) --- CHANGELOG | 1 + program/include/rcmail.php | 14 +++++++++++--- program/js/app.js | 4 ++++ program/localization/en_US/messages.inc | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fc683ef03..5dabc9e09 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Display error when trying to upload more files than specified in max_file_uploads (#5483) - Add missing sql upgrade file for 'ip' column resize in session table (#5465) - Do not show inline images of unsupported mimetype (#5463) - Password: Added LDAP PPolicy driver (#5364) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 4402da0f6..a6d07695f 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -2061,6 +2061,8 @@ class rcmail extends rcube * Initializes file uploading interface. * * @param int $max_size Optional maximum file size in bytes + * + * @return string Human-readable file size limit */ public function upload_init($max_size = null) { @@ -2088,12 +2090,18 @@ class rcmail extends rcube $max_filesize = $max_size; } + $max_filesize_txt = $this->show_bytes($max_filesize); $this->output->set_env('max_filesize', $max_filesize); - $max_filesize = $this->show_bytes($max_filesize); $this->output->set_env('filesizeerror', $this->gettext(array( - 'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize)))); + 'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize_txt)))); + + if ($max_filecount = ini_get('max_file_uploads')) { + $this->output->set_env('max_filecount', $max_filecount); + $this->output->set_env('filecounterror', $this->gettext(array( + 'name' => 'filecounterror', 'vars' => array('count' => $max_filecount)))); + } - return $max_filesize; + return $max_filesize_txt; } /** diff --git a/program/js/app.js b/program/js/app.js index 6e000d83e..844973569 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -4876,6 +4876,10 @@ function rcube_webmail() this.display_message(this.env.filesizeerror, 'error'); return false; } + if (this.env.max_filecount && this.env.filecounterror && numfiles > this.env.max_filecount) { + this.display_message(this.env.filecounterror, 'error'); + return false; + } var frame_name = this.async_upload_form(form, action || 'upload', function(e) { var d, content = ''; diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc index ccf931776..945bb22c2 100644 --- a/program/localization/en_US/messages.inc +++ b/program/localization/en_US/messages.inc @@ -119,6 +119,7 @@ $messages['messageopenerror'] = 'Could not load message from server.'; $messages['filelinkerror'] = 'Attaching the file failed.'; $messages['fileuploaderror'] = 'File upload failed.'; $messages['filesizeerror'] = 'The uploaded file exceeds the maximum size of $size.'; +$messages['filecounterror'] = 'You can upload maximum $count files at once.'; $messages['msgsizeerror'] = 'Failed to attach a file. Maximum size of a message ($size) exceeded.'; $messages['copysuccess'] = 'Successfully copied $nr contacts.'; $messages['movesuccess'] = 'Successfully moved $nr contacts.';