From 7f3f32af952da799c08bc5f3761e380fd90f8fa7 Mon Sep 17 00:00:00 2001 From: Jan BELLON Date: Tue, 12 Mar 2024 09:27:29 +0000 Subject: [PATCH] Update file editpage.php --- html/editpage.php | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/html/editpage.php b/html/editpage.php index 16b5f175..47660e24 100644 --- a/html/editpage.php +++ b/html/editpage.php @@ -29,6 +29,47 @@ if(isset($_GET['page']) && strpos($_GET['page'], "..") == false) { } } +if (isset($_FILES['miniature']) && $_FILES['miniature']['error'] == 0 && isset($_GET['article'])) { + // Chemins et noms de fichiers + $tempPath = $_FILES['miniature']['tmp_name']; + $path = '/src/miniature/'. $_SESSION['userid'] .'.png'; + $rootPath = $wwwroot . "/html" . $path; + $webPath = $root . $path; + + // Redimensionnement de l'image + list($width, $height) = getimagesize($tempPath); + $imageInfo = getimagesize($tempPath); + + if ($imageInfo[2] === IMAGETYPE_PNG || $imageInfo[2] === IMAGETYPE_JPEG) { + $newWidth = 600; + $newHeight = ($height / $width) * $newWidth; + $imageResized = imagecreatetruecolor($newWidth, $newHeight); + imagealphablending($imageResized, false); + imagesavealpha($imageResized, true); + $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, $rootPath); + + // Nettoyage + imagedestroy($imageOriginal); + imagedestroy($imageResized); + + $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); + $req = $bdd->prepare("UPDATE articles SET image = :image WHERE ID = :article"); + $req->bindParam(":image", $webPath); + $req->bindParam(":article", $_GET['article']); + if($req->execute()) { + $status = "Miniature mise à jour"; + } else { + $status = "Erreur SQL"; + } + } else { + $status = "Le fichier doit être un PNG ou JPG"; + } +} + $filename = isset($filename) ? $filename : ""; if(isset($fichier)) { @@ -124,7 +165,7 @@ if(isset($fichier)) {
-
+
'; @@ -151,13 +192,18 @@ if(isset($fichier)) { $filetitle = $resultat[0]['titre']; echo '
'; - echo '
'; echo '
'; } } echo "

" . $filetitle . "

"; echo '
'; echo '
'; + if($resultat) { + echo '
'; + echo ''; + echo ''; + echo '
'; + } } else { echo "

Pages

"; echo "
";