From a5f02d7c3e4f0a40e545b6bdc5b29672c7f203c4 Mon Sep 17 00:00:00 2001 From: Jan BELLON Date: Tue, 12 Mar 2024 09:16:51 +0000 Subject: [PATCH] Update file compte.php --- html/compte.php | 52 ++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/html/compte.php b/html/compte.php index 4bbe917d..fc432601 100644 --- a/html/compte.php +++ b/html/compte.php @@ -55,30 +55,36 @@ if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] == // Redimensionnement de l'image list($width, $height) = getimagesize($tempPath); - - $newWidth = 128; - $newHeight = 128; - $imageResized = imagecreatetruecolor($newWidth, $newHeight); - $imageOriginal = imagecreatefromstring(file_get_contents($tempPath)); - imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); - imagealphablending($imageResized, false); - imagesavealpha($imageResized, true); - // Enregistrement de l'image redimensionnée - imagepng($imageResized, $rootPath); + $imageInfo = getimagesize($tempPath); - // Nettoyage - imagedestroy($imageOriginal); - imagedestroy($imageResized); + if ($imageInfo[2] === IMAGETYPE_PNG || $imageInfo[2] === IMAGETYPE_JPEG) { + $newWidth = 128; + $newHeight = 128; + $imageResized = imagecreatetruecolor($newWidth, $newHeight); + $imageOriginal = imagecreatefromstring(file_get_contents($tempPath)); + imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); + imagealphablending($imageResized, false); + imagesavealpha($imageResized, true); - $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); - $req = $bdd->prepare("UPDATE users SET profile_picture = :user_pp WHERE ID = :user_id"); - $req->bindParam(":user_pp", $webPath); - $req->bindParam(":user_id", $_SESSION['userid']); - if($req->execute()) { - $status = "PP mise à jour"; + // Enregistrement de l'image redimensionnée + imagepng($imageResized, $rootPath); + + // Nettoyage + imagedestroy($imageOriginal); + imagedestroy($imageResized); + + $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); + $req = $bdd->prepare("UPDATE users SET profile_picture = :user_pp WHERE ID = :user_id"); + $req->bindParam(":user_pp", $webPath); + $req->bindParam(":user_id", $_SESSION['userid']); + if($req->execute()) { + $status = "PP mise à jour"; + } else { + $status = "Erreur SQL"; + } } else { - $status = "Erreur SQL"; + $status = "Le fichier doit être au format PNG ou JPG"; } } @@ -91,6 +97,9 @@ if (isset($_FILES['banner']) && $_FILES['banner']['error'] == 0) { // Redimensionnement de l'image list($width, $height) = getimagesize($tempPath); + $imageInfo = getimagesize($tempPath); + + if ($imageInfo[2] === IMAGETYPE_PNG || $imageInfo[2] === IMAGETYPE_JPEG) { $newWidth = 800; $newHeight = ($height / $width) * $newWidth; $imageResized = imagecreatetruecolor($newWidth, $newHeight); @@ -115,6 +124,9 @@ if (isset($_FILES['banner']) && $_FILES['banner']['error'] == 0) { } else { $status = "Erreur SQL"; } + } else { + $status = "Le fichier doit être un PNG ou JPG" + } } ?>