prepare("SELECT ID, username, creation_date, display_name, role, profile_picture, banner, bio FROM users WHERE ID = :user_id"); $req->bindParam(":user_id", $_SESSION['userid']); $req->execute(); $resultat = $req->fetchAll(PDO::FETCH_ASSOC); if($resultat) { $user_id = $resultat[0]['ID']; $user_name = $resultat[0]['username']; $user_creation_date = $resultat[0]['creation_date']; $user_display_name = $resultat[0]['display_name']; $user_role = $resultat[0]['role']; $user_pp = $resultat[0]['profile_picture'] == NULL ? "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png" : $resultat[0]['profile_picture']; $user_pp_url = $resultat[0]['profile_picture']; $user_banner = $resultat[0]['banner'] = NULL ? "./src/img/empty.jpg" : $resultat[0]['banner']; $user_bio = $resultat[0]['bio']; } else { die("Erreur, utilisateur introuvable"); } if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_POST['user_bio'])) { $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("SELECT ID FROM users WHERE username = :user_name AND NOT ID = :user_id"); $req->bindParam(":user_name", htmlspecialchars($_POST['user_name'])); $req->bindParam(":user_id", $_SESSION['userid'], PDO::PARAM_INT); $req->execute(); $resultat = $req->fetchAll(PDO::FETCH_ASSOC); if($resultat) { $status = "Erreur, le nom d'utilisateur existe déjà."; } else { $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("UPDATE users SET username = :user_name, display_name = :user_display_name, bio = :user_bio WHERE ID = :user_id"); $req->bindParam(":user_name", htmlspecialchars($_POST['user_name'])); $req->bindParam(":user_display_name", htmlspecialchars($_POST['user_display_name'])); $req->bindParam(":user_bio", htmlspecialchars($_POST['user_bio'])); $req->bindParam(":user_id", $_SESSION['userid']); if($req->execute()) { $status = "Informations mises à jour"; } else { $status = "Erreur, les informations n'ont pas pu être mises à jour."; } } } 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"; } ?>