From ae39544e10b0043a56c478bdf51183b024435b42 Mon Sep 17 00:00:00 2001 From: Manfred Hoffmann <48651533+manne65-hd@users.noreply.github.com> Date: Tue, 20 Apr 2021 07:42:58 +0200 Subject: [PATCH] Catch error when trying to upload empty or invalid avatar --- app/Controller/AvatarFileController.php | 10 ++++++++-- app/Locale/bs_BA/translations.php | 2 ++ app/Locale/ca_ES/translations.php | 2 ++ app/Locale/cs_CZ/translations.php | 2 ++ app/Locale/da_DK/translations.php | 2 ++ app/Locale/de_DE/translations.php | 2 ++ app/Locale/de_DE_du/translations.php | 2 ++ app/Locale/el_GR/translations.php | 2 ++ app/Locale/es_ES/translations.php | 2 ++ app/Locale/es_VE/translations.php | 2 ++ app/Locale/fa_IR/translations.php | 2 ++ app/Locale/fi_FI/translations.php | 2 ++ app/Locale/fr_FR/translations.php | 2 ++ app/Locale/hr_HR/translations.php | 2 ++ app/Locale/hu_HU/translations.php | 2 ++ app/Locale/id_ID/translations.php | 2 ++ app/Locale/it_IT/translations.php | 2 ++ app/Locale/ja_JP/translations.php | 2 ++ app/Locale/ko_KR/translations.php | 2 ++ app/Locale/mk_MK/translations.php | 2 ++ app/Locale/my_MY/translations.php | 2 ++ app/Locale/nb_NO/translations.php | 2 ++ app/Locale/nl_NL/translations.php | 2 ++ app/Locale/pl_PL/translations.php | 2 ++ app/Locale/pt_BR/translations.php | 2 ++ app/Locale/pt_PT/translations.php | 2 ++ app/Locale/ro_RO/translations.php | 2 ++ app/Locale/ru_RU/translations.php | 2 ++ app/Locale/sk_SK/translations.php | 2 ++ app/Locale/sr_Latn_RS/translations.php | 2 ++ app/Locale/sv_SE/translations.php | 2 ++ app/Locale/th_TH/translations.php | 2 ++ app/Locale/tr_TR/translations.php | 2 ++ app/Locale/uk_UA/translations.php | 2 ++ app/Locale/vi_VN/translations.php | 2 ++ app/Locale/zh_CN/translations.php | 2 ++ app/Locale/zh_TW/translations.php | 2 ++ app/Model/AvatarFileModel.php | 20 ++++++++++++++++++++ 38 files changed, 100 insertions(+), 2 deletions(-) diff --git a/app/Controller/AvatarFileController.php b/app/Controller/AvatarFileController.php index 12c4069c3..99a2cfb96 100644 --- a/app/Controller/AvatarFileController.php +++ b/app/Controller/AvatarFileController.php @@ -33,8 +33,14 @@ class AvatarFileController extends BaseController $this->checkCSRFParam(); $user = $this->getUser(); - if (! $this->avatarFileModel->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) { - $this->flash->failure(t('Unable to upload files, check the permissions of your data folder.')); + if (! $this->request->getFileInfo('avatar')['name']) { + $this->flash->failure(t('You must select a file to upload as your avatar!')); + } elseif (! $this->avatarFileModel->isAvatarImage($this->request->getFileInfo('avatar')['name'])) { + $this->flash->failure(t('The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)')); + } else { + if (! $this->avatarFileModel->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) { + $this->flash->failure(t('Unable to upload files, check the permissions of your data folder.')); + } } $this->renderResponse($user['id']); diff --git a/app/Locale/bs_BA/translations.php b/app/Locale/bs_BA/translations.php index dc5ec05fd..002b62fca 100644 --- a/app/Locale/bs_BA/translations.php +++ b/app/Locale/bs_BA/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/ca_ES/translations.php b/app/Locale/ca_ES/translations.php index 0d50b5c9d..0d586c44a 100644 --- a/app/Locale/ca_ES/translations.php +++ b/app/Locale/ca_ES/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/cs_CZ/translations.php b/app/Locale/cs_CZ/translations.php index 0bfdbcca6..217442fb1 100644 --- a/app/Locale/cs_CZ/translations.php +++ b/app/Locale/cs_CZ/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index ccdd52c1c..1ad96085b 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 1de10f334..b9bad2c01 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + 'You must select a file to upload as your avatar!' => 'Sie müssen eine Datei auswählen, die als Avatar hochgeladen werden soll!', + 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => 'Die hochgeladene Datei ist kein gültiges Bild! (Nur *.gif, *.jpg, *.jpeg and *.png sind erlaubt!)', ); diff --git a/app/Locale/de_DE_du/translations.php b/app/Locale/de_DE_du/translations.php index b76b56d68..2c2b0e5e3 100644 --- a/app/Locale/de_DE_du/translations.php +++ b/app/Locale/de_DE_du/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + 'You must select a file to upload as your avatar!' => 'Du musst eine Datei auswählen, die als Avatar hochgeladen werden soll!', + 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => 'Die hochgeladene Datei ist kein gültiges Bild! (Nur *.gif, *.jpg, *.jpeg and *.png sind erlaubt!)', ); diff --git a/app/Locale/el_GR/translations.php b/app/Locale/el_GR/translations.php index 4af5ae420..5f64e1301 100644 --- a/app/Locale/el_GR/translations.php +++ b/app/Locale/el_GR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index 34f93f0cd..9173b5ed5 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/es_VE/translations.php b/app/Locale/es_VE/translations.php index 436e9f2ce..47c0e3812 100644 --- a/app/Locale/es_VE/translations.php +++ b/app/Locale/es_VE/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/fa_IR/translations.php b/app/Locale/fa_IR/translations.php index 6355c1e6b..14e747f63 100644 --- a/app/Locale/fa_IR/translations.php +++ b/app/Locale/fa_IR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - بیت کوین', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index d61077f85..c90d5a86a 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 148e638ee..428e44e0a 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -1427,4 +1427,6 @@ return array( 'Estimated vs actual time per column' => 'Temps estimé vs temps réel par colonne', 'HUF - Hungarian Forint' => 'HUF - Forint hongrois', 'XBT - Bitcoin' => 'XBT - Bitcoin', + 'You must select a file to upload as your avatar!' => 'Vous devez sélectionner un fichier à télécharger pour votre avatar !', + 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => 'Le fichier que vous avez téléchargé n\'est pas une image valide ! (Seuls * .gif, * .jpg, * .jpeg et * .png sont autorisés !)', ); diff --git a/app/Locale/hr_HR/translations.php b/app/Locale/hr_HR/translations.php index 0cd680f04..a2af7ee53 100644 --- a/app/Locale/hr_HR/translations.php +++ b/app/Locale/hr_HR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 79705f706..4c2aa55f6 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', 'HUF - Hungarian Forint' => 'HUF – magyar forint', 'XBT - Bitcoin' => 'XBT – Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/id_ID/translations.php b/app/Locale/id_ID/translations.php index e11389256..fd1e2b2e4 100644 --- a/app/Locale/id_ID/translations.php +++ b/app/Locale/id_ID/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index a96d880de..dad8da894 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 266fc2fea..b1cbfc19d 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/ko_KR/translations.php b/app/Locale/ko_KR/translations.php index 667db845e..5a54252e5 100644 --- a/app/Locale/ko_KR/translations.php +++ b/app/Locale/ko_KR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/mk_MK/translations.php b/app/Locale/mk_MK/translations.php index f3c291b6f..494d11e4b 100644 --- a/app/Locale/mk_MK/translations.php +++ b/app/Locale/mk_MK/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - биткоин', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/my_MY/translations.php b/app/Locale/my_MY/translations.php index 357ca232b..c3618215b 100644 --- a/app/Locale/my_MY/translations.php +++ b/app/Locale/my_MY/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/nb_NO/translations.php b/app/Locale/nb_NO/translations.php index 038ecc786..f19a7b735 100644 --- a/app/Locale/nb_NO/translations.php +++ b/app/Locale/nb_NO/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index cfc8c53ab..db40f5750 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 6bac9cf05..c8fe1790b 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 0bcfc89f1..dc3888818 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/pt_PT/translations.php b/app/Locale/pt_PT/translations.php index 36b54d548..e832b3f4f 100644 --- a/app/Locale/pt_PT/translations.php +++ b/app/Locale/pt_PT/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/ro_RO/translations.php b/app/Locale/ro_RO/translations.php index 8b1ed48ab..c59e1131d 100644 --- a/app/Locale/ro_RO/translations.php +++ b/app/Locale/ro_RO/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 982f9e5ca..57d2f31ca 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Биткоин', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/sk_SK/translations.php b/app/Locale/sk_SK/translations.php index 5e4e51b30..888c13025 100644 --- a/app/Locale/sk_SK/translations.php +++ b/app/Locale/sk_SK/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT – Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index e273fd415..a15a41720 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitkoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 734f42162..1132334d1 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 2a949524a..7e0f40b3f 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index 552748f43..c82309095 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - Bitcoin', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/uk_UA/translations.php b/app/Locale/uk_UA/translations.php index 78dc6381c..e7fad60ea 100644 --- a/app/Locale/uk_UA/translations.php +++ b/app/Locale/uk_UA/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT – Біткоїн', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/vi_VN/translations.php b/app/Locale/vi_VN/translations.php index 8c217a505..92e536df4 100644 --- a/app/Locale/vi_VN/translations.php +++ b/app/Locale/vi_VN/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index c723912f0..8e4db85a4 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', 'XBT - Bitcoin' => 'XBT - 比特币', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Locale/zh_TW/translations.php b/app/Locale/zh_TW/translations.php index 3ff5c0e26..45f4f14ef 100644 --- a/app/Locale/zh_TW/translations.php +++ b/app/Locale/zh_TW/translations.php @@ -1427,4 +1427,6 @@ return array( // 'Estimated vs actual time per column' => '', // 'HUF - Hungarian Forint' => '', // 'XBT - Bitcoin' => '', + // 'You must select a file to upload as your avatar!' => '', + // 'The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)' => '', ); diff --git a/app/Model/AvatarFileModel.php b/app/Model/AvatarFileModel.php index 6e36d83f7..923e63938 100644 --- a/app/Model/AvatarFileModel.php +++ b/app/Model/AvatarFileModel.php @@ -136,4 +136,24 @@ class AvatarFileModel extends Base { return implode(DIRECTORY_SEPARATOR, array(self::PATH_PREFIX, $user_id, hash('sha1', $filename.time()))); } + + /** + * Check if a filename is an image (file types that can be shown as avatar) + * + * @access public + * @param string $filename Filename + * @return bool + */ + public function isAvatarImage($filename) + { + switch (get_file_extension($filename)) { + case 'jpeg': + case 'jpg': + case 'png': + case 'gif': + return true; + } + + return false; + } }