Update file compte.php

This commit is contained in:
Jan BELLON 2024-03-12 09:16:51 +00:00
parent 6f6b5df137
commit a5f02d7c3e

View File

@ -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"
}
}
?>