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)) { - + =$status?> '; @@ -151,13 +192,18 @@ if(isset($fichier)) { $filetitle = $resultat[0]['titre']; echo 'Titre : '; - echo 'Couverture : '; echo '' . str_replace("", "", $resultat[0]['resume']) . ''; } } echo "" . $filetitle . ""; echo '' . str_replace("", "", $contenu) . ''; echo ''; + if($resultat) { + echo ''; + echo ''; + echo ''; + echo ''; + } } else { echo "Pages"; echo "";