diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-10-15 21:44:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-15 21:44:48 +0200 |
commit | 1b2568e6370f592d0be0e7e103c0e3ed073d2a71 (patch) | |
tree | 3ecf659ad5acd17ec35735ea56c3d966b98e982c /apps/theming/lib/Controller | |
parent | a5912cbe33649236dd3edf284b1182d7cf39819b (diff) | |
parent | f15e85c4f50b6c9e77742e15f8291a8628a28ef7 (diff) | |
download | nextcloud-server-1b2568e6370f592d0be0e7e103c0e3ed073d2a71.tar.gz nextcloud-server-1b2568e6370f592d0be0e7e103c0e3ed073d2a71.zip |
Merge pull request #6585 from nextcloud/theming-fileupload-errorhandling
Theming: Handle errors on uploaded files properly
Diffstat (limited to 'apps/theming/lib/Controller')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 06c2c430b7f..ccc2634ec14 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -207,12 +207,34 @@ class ThemingController extends Controller { } $newLogo = $this->request->getUploadedFile('uploadlogo'); $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); + $error = null; + $phpFileUploadErrors = [ + UPLOAD_ERR_OK => $this->l10n->t('There is no error, the file uploaded with success'), + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), + UPLOAD_ERR_PARTIAL => $this->l10n->t('The uploaded file was only partially uploaded'), + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Failed to write file to disk.'), + UPLOAD_ERR_EXTENSION => $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 + ], + 'status' => 'failure', ], Http::STATUS_UNPROCESSABLE_ENTITY ); @@ -227,6 +249,18 @@ class ThemingController extends Controller { if (!empty($newLogo)) { $target = $folder->newFile('logo'); + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; + if (!in_array($newLogo['type'], $supportedFormats)) { + return new DataResponse( + [ + 'data' => [ + 'message' => $this->l10n->t('Unsupported image type'), + ], + 'status' => 'failure', + ], + Http::STATUS_UNPROCESSABLE_ENTITY + ); + } $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); $this->themingDefaults->set('logoMime', $newLogo['type']); $name = $newLogo['name']; |