summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/Controller/ThemingController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming/lib/Controller/ThemingController.php')
-rw-r--r--apps/theming/lib/Controller/ThemingController.php38
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'];