show informative errors in log and UI on avatar upload error in user settings

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier 2021-04-01 11:42:39 +02:00
parent 68d3640076
commit 7b69897474
No known key found for this signature in database
GPG Key ID: 4141FEE162030638
1 changed files with 13 additions and 1 deletions

View File

@ -193,8 +193,20 @@ class AvatarController extends Controller {
$content = $this->cache->get('avatar_upload'); $content = $this->cache->get('avatar_upload');
unlink($files['tmp_name'][0]); unlink($files['tmp_name'][0]);
} else { } else {
$phpFileUploadErrors = [
UPLOAD_ERR_OK => $this->l->t('The file was uploaded'),
UPLOAD_ERR_INI_SIZE => $this->l->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
UPLOAD_ERR_FORM_SIZE => $this->l->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
UPLOAD_ERR_PARTIAL => $this->l->t('The file was only partially uploaded'),
UPLOAD_ERR_NO_FILE => $this->l->t('No file was uploaded'),
UPLOAD_ERR_NO_TMP_DIR => $this->l->t('Missing a temporary folder'),
UPLOAD_ERR_CANT_WRITE => $this->l->t('Could not write file to disk'),
UPLOAD_ERR_EXTENSION => $this->l->t('A PHP extension stopped the file upload'),
];
$message = $phpFileUploadErrors[$files['error'][0]] ?? $this->l->t('Invalid file provided');
$this->logger->warning($message, ['app' => 'core']);
return new JSONResponse( return new JSONResponse(
['data' => ['message' => $this->l->t('Invalid file provided')]], ['data' => ['message' => $message]],
Http::STATUS_BAD_REQUEST Http::STATUS_BAD_REQUEST
); );
} }