diff --git a/html/compte.php b/html/compte.php index 2cc95237..0a9cebad 100644 --- a/html/compte.php +++ b/html/compte.php @@ -48,6 +48,73 @@ if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_P } } +if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] == 0) { + // Chemins et noms de fichiers + $tempPath = $_FILES['profile_picture']['tmp_name']; + $path = 'src/pp/'. $_SESSION['userid'] .'.png'; + $finalPath = $wwwroot . $path; + + // Redimensionnement de l'image + $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); + + // Enregistrement de l'image redimensionnée + imagepng($imageResized, $finalPath); + + // 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", $path); + $req->bindParam(":user_id", $_SESSION['userid']); + if($req->execute()) { + $status "PP mise à jour"; + } else { + $status = "Erreur SQL"; + } +} else { + echo "Erreur upload"; +} + +if (isset($_FILES['banner']) && $_FILES['banner']['error'] == 0) { + // Chemins et noms de fichiers + $tempPath = $_FILES['banner']['tmp_name']; + $path = 'src/pp/'. $_SESSION['userid'] .'.png'; + $finalPath = $wwwroot . $path; + + // Redimensionnement de l'image + list($width, $height) = getimagesize($tempPath); + $newWidth = 600; + $newHeight = ($height / $width) * $newWidth; + $imageResized = imagecreatetruecolor($newWidth, $newHeight); + $imageOriginal = imagecreatefromstring(file_get_contents($tempPath)); + imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); + + // Enregistrement de l'image redimensionnée + imagepng($imageResized, $finalPath); + + // Nettoyage + imagedestroy($imageOriginal); + imagedestroy($imageResized); + + $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); + $req = $bdd->prepare("UPDATE users SET banner = :user_banner WHERE ID = :user_id"); + $req->bindParam(":user_banner", $path); + $req->bindParam(":user_id", $_SESSION['userid']); + if($req->execute()) { + $status "Banière mise à jour"; + } else { + $status = "Erreur SQL"; + } +} else { + echo "Erreur upload"; +} + ?> @@ -144,8 +211,9 @@ if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_P
- - + + +