diff options
author | Julius Härtl <jus@bitgrid.net> | 2017-09-20 12:32:41 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2017-10-03 15:32:50 +0200 |
commit | c337c8fa454366384bec12e889e4dd371c0a67f7 (patch) | |
tree | 7019ce7d0fdf93b6a4a5d5af53fc2209b9201483 /apps/theming/lib | |
parent | 42bd94261904574d807d9cf1917f6283b08287ac (diff) | |
download | nextcloud-server-c337c8fa454366384bec12e889e4dd371c0a67f7.tar.gz nextcloud-server-c337c8fa454366384bec12e889e4dd371c0a67f7.zip |
Theming: Handle errors on uploaded files properly
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 06c2c430b7f..e73fc16b20b 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -207,11 +207,32 @@ class ThemingController extends Controller { } $newLogo = $this->request->getUploadedFile('uploadlogo'); $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); + $error = null; + $phpFileUploadErrors = array( + 0 => $this->l10n->t('There is no error, the file uploaded with success'), + 1 => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), + 2 => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), + 3 => $this->l10n->t('The uploaded file was only partially uploaded'), + 4 => $this->l10n->t('No file was uploaded'), + 6 => $this->l10n->t('Missing a temporary folder'), + 7 => $this->l10n->t('Failed to write file to disk.'), + 8 => $this->l10n->t('A PHP extension stopped the file upload.'), + ); if (empty($newLogo) && empty($newBackgroundLogo)) { + $error = $this->l10n->t('No file uploaded'); + } + if (!empty($newLogo) && array_key_exists('error', $newLogo) && $newLogo['error'] !== UPLOAD_ERR_OK) { + $error = $phpFileUploadErrors[$newLogo['error']]; + } + if (!empty($newBackgroundLogo) && array_key_exists('error', $newBackgroundLogo) && $newBackgroundLogo['error'] !== UPLOAD_ERR_OK) { + $error = $phpFileUploadErrors[$newBackgroundLogo['error']]; + } + + if ($error !== null) { return new DataResponse( [ 'data' => [ - 'message' => $this->l10n->t('No file uploaded') + 'message' => $error ] ], Http::STATUS_UNPROCESSABLE_ENTITY |