From 33ac06bc2c271205dd66dacbd2cdc8963790af8b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 12 Mar 2019 18:29:13 -0600 Subject: [PATCH] Handle empty files due to upload_max_filesize --- CHANGELOG.md | 1 + classes/admincontroller.php | 9 +++++++++ languages/en.yaml | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e468c5..c41d0942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Improved image background overlay and tools * Update all Form classes to rely on `PageInterface` instead of `Page` class * Removed `media.upload_limit` references + * Improve error when upload exceeds `upload_max_filesize` 1. [](#bugfix) * Incorrect 2FA lang code [#1618](https://github.com/getgrav/grav-plugin-admin/issues/1618) * Fixed potential undefined property in `onPageNotFound` event handling diff --git a/classes/admincontroller.php b/classes/admincontroller.php index 7a2ac89c..7762aefa 100644 --- a/classes/admincontroller.php +++ b/classes/admincontroller.php @@ -1567,6 +1567,15 @@ class AdminController extends AdminBaseController /** @var Config $config */ $config = $this->grav['config']; + if (!isset($_FILES) || empty($_FILES)) { + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin::translate('PLUGIN_ADMIN.EXCEEDED_POSTMAX_LIMIT') + ]; + + return false; + } + if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) { $this->admin->json_response = [ 'status' => 'error', diff --git a/languages/en.yaml b/languages/en.yaml index beae32bb..edb507da 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -178,7 +178,8 @@ PLUGIN_ADMIN: NO_PAGE_FOUND: "No Page found" INVALID_PARAMETERS: "Invalid Parameters" NO_FILES_SENT: "No files sent" - EXCEEDED_FILESIZE_LIMIT: "Exceeded PHP configuration file size limit" + EXCEEDED_FILESIZE_LIMIT: "Exceeded PHP configuration upload_max_filesize" + EXCEEDED_POSTMAX_LIMIT: "Exceeded PHP configuration post_max_size" UNKNOWN_ERRORS: "Unknown errors" EXCEEDED_GRAV_FILESIZE_LIMIT: "Exceeded Grav configuration file size limit" UNSUPPORTED_FILE_TYPE: "Unsupported file type"