From fed88a764ba0e45d0b4bdddc62c7ed27aa951831 Mon Sep 17 00:00:00 2001 From: Yasder5 <102179445+Yasder5@users.noreply.github.com> Date: Mon, 23 Feb 2026 19:43:44 +0100 Subject: [PATCH] =?UTF-8?q?oops=20j'ai=20oubli=C3=A9=20de=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/user_controller.php | 72 ++++++++++++++++++ models/user_model.php | 4 +- ...94486bfa02ee91c2c5fe68_0.file_home.tpl.php | 12 +-- ...82584009ce981aa35e0b_0.file_layout.tpl.php | 12 +-- ...56e3cf6837f9df55d7fb_0.file_footer.tpl.php | 8 +- ...2993687bad91a1cf0f6_0.file_preview.tpl.php | 14 ++-- ...947735d13c8d176ec944_0.file_header.tpl.php | 13 ++-- uploads/profiles/699b019dc6db1.webp | Bin 0 -> 2784 bytes uploads/profiles/699b020302a4e.webp | Bin 0 -> 2784 bytes uploads/profiles/699b028f54007.webp | Bin 0 -> 5710 bytes uploads/profiles/thomas.jpg | Bin 8898 -> 0 bytes views/_partial/header.tpl | 4 +- views/_partial/preview.tpl | 4 +- views/user.tpl | 2 +- views/useredit.tpl | 20 ++++- 15 files changed, 130 insertions(+), 35 deletions(-) create mode 100644 uploads/profiles/699b019dc6db1.webp create mode 100644 uploads/profiles/699b020302a4e.webp create mode 100644 uploads/profiles/699b028f54007.webp delete mode 100644 uploads/profiles/thomas.jpg diff --git a/controllers/user_controller.php b/controllers/user_controller.php index 6b7d42d..1ccd6b2 100644 --- a/controllers/user_controller.php +++ b/controllers/user_controller.php @@ -217,9 +217,81 @@ class UserCtrl extends MotherCtrl { }else{ $objUser->hydrate($_POST); $objUser->setId($_SESSION['user']['user_id']); + + // Vérification de l'image + $arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp'); + $boolImageOk = true; + + if ($_FILES['image']['error'] != 4) { + if (!in_array($_FILES['image']['type'], $arrTypeAllowed)) { + $arrError['image'] = "Le type de fichier n'est pas autorisé"; + } else { + switch ($_FILES['image']['error']) { + case 0: + $strImageName = uniqid() . ".webp"; + $strOldImg = $objUser->getImage(); + $objUser->setImage($strImageName); + break; + case 1: + case 2: + $arrError['image'] = "Le fichier est trop volumineux"; + break; + case 3: + $arrError['image'] = "Le fichier a été partiellement téléchargé"; + break; + case 6: + $arrError['image'] = "Le répertoire temporaire est manquant"; + break; + default: + $arrError['image'] = "Erreur sur l'image"; + break; + } + } + } + + // Traitement de l'image si pas d'erreur + if (count($arrError) == 0 && isset($strImageName)) { + $strDest = $_ENV['IMG_USER_PATH'] . $strImageName; + $strSource = $_FILES['image']['tmp_name']; + list($intWidth, $intHeight) = getimagesize($strSource); + + $intDestWidth = 200; $intDestHeight = 200; + $fltDestRatio = $intDestWidth / $intDestHeight; + $fltSourceRatio = $intWidth / $intHeight; + + if ($fltSourceRatio > $fltDestRatio) { + $intCropHeight = $intHeight; + $intCropWidth = (int)round($intHeight * $fltDestRatio); + $intCropX = (int)(($intWidth - $intCropWidth) / 2); + $intCropY = 0; + } else { + $intCropWidth = $intWidth; + $intCropHeight = (int)round($intWidth / $fltDestRatio); + $intCropX = 0; + $intCropY = (int)(($intHeight - $intCropHeight) / 2); + } + + $objDest = imagecreatetruecolor($intDestWidth, $intDestHeight); + switch ($_FILES['image']['type']) { + case 'image/jpeg': $objSource = imagecreatefromjpeg($strSource); break; + case 'image/png': $objSource = imagecreatefrompng($strSource); break; + case 'image/webp': $objSource = imagecreatefromwebp($strSource); break; + } + + imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight); + $boolImageOk = imagewebp($objDest, $strDest); + imagedestroy($objDest); + imagedestroy($objSource); + } + + $boolInsert = $objUserModel->update($objUser); if ($boolInsert === true) { + if (isset($strOldImg) && !empty($strOldImg) && isset($strImageName)) { + $strOldFile = $_ENV['IMG_USER_PATH'] . $strOldImg; + if (file_exists($strOldFile)) unlink($strOldFile); + } $arrNewInfo = $objUserModel->findUserByPseudo($objUser->getPseudo()); $_SESSION['user'] = $arrNewInfo; $_SESSION['success'] = "Compte modifier avec succès"; diff --git a/models/user_model.php b/models/user_model.php index 295cb2a..f17b9a3 100644 --- a/models/user_model.php +++ b/models/user_model.php @@ -79,7 +79,8 @@ user_phone = :phone, user_work = :work, user_location = :location, - user_description = :description + user_description = :description, + user_image = :image WHERE user_id = :id"; @@ -94,6 +95,7 @@ $rqPrep->bindValue(':work', $objUser->getWork() ?? "", PDO::PARAM_STR); $rqPrep->bindValue(':location', $objUser->getLocation() ?? "", PDO::PARAM_STR); $rqPrep->bindValue(':description', $objUser->getDescription() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':image', $objUser->getImage() ?? "", PDO::PARAM_STR); return $rqPrep->execute(); diff --git a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php index c777847..aba8e34 100644 --- a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php +++ b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_69978fa60745f2_12751511', + 'unifunc' => 'content_699b41bcd91c72_02975929', 'has_nocache_code' => false, 'file_dependency' => array ( '0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68' => array ( 0 => 'views/home.tpl', - 1 => 1771519241, + 1 => 1771764865, 2 => 'file', ), ), @@ -21,20 +21,20 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/preview.tpl' => 1, ), ))) { -function content_69978fa60745f2_12751511 (\Smarty\Template $_smarty_tpl) { +function content_699b41bcd91c72_02975929 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_71856491269978fa6070479_42524298', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_1323497504699b41bcd807a2_70028595', "content"); ?> getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); } /* {block "content"} */ -class Block_71856491269978fa6070479_42524298 extends \Smarty\Runtime\Block +class Block_1323497504699b41bcd807a2_70028595 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; diff --git a/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php b/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php index d5cd0ad..b528190 100644 --- a/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php +++ b/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_69979176184d29_24146176', + 'unifunc' => 'content_699b41bce4c480_92970054', 'has_nocache_code' => false, 'file_dependency' => array ( '1c51ad9f5c349145220f82584009ce981aa35e0b' => array ( 0 => 'views/layout.tpl', - 1 => 1771520226, + 1 => 1771764865, 2 => 'file', ), ), @@ -22,21 +22,21 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/footer.tpl' => 1, ), ))) { -function content_69979176184d29_24146176 (\Smarty\Template $_smarty_tpl) { +function content_699b41bce4c480_92970054 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, false); $_smarty_tpl->renderSubTemplate("file:views/_partial/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_109821553569979176183258_93965722', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_734818017699b41bce4aba1_89981806', "content"); ?> renderSubTemplate("file:views/_partial/footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir); } /* {block "content"} */ -class Block_109821553569979176183258_93965722 extends \Smarty\Runtime\Block +class Block_734818017699b41bce4aba1_89981806 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; diff --git a/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php b/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php index 035cae9..11708bb 100644 --- a/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php +++ b/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_69979176449a68_71315247', + 'unifunc' => 'content_699b41bd21fcf8_20527700', 'has_nocache_code' => false, 'file_dependency' => array ( '264314e384c04e79c5fa56e3cf6837f9df55d7fb' => array ( 0 => 'views/_partial/footer.tpl', - 1 => 1771519241, + 1 => 1771764865, 2 => 'file', ), ), @@ -20,7 +20,7 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( array ( ), ))) { -function content_69979176449a68_71315247 (\Smarty\Template $_smarty_tpl) { +function content_699b41bd21fcf8_20527700 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views\\_partial'; ?>