Update file editpage.php
This commit is contained in:
parent
33ca964ed4
commit
7f3f32af95
@ -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)) {
|
||||
<main>
|
||||
<div class="content">
|
||||
<div>
|
||||
<div>
|
||||
<div><div><?=$status?></div>
|
||||
<?php
|
||||
if(isset($contenu)) {
|
||||
echo '<form action="?' . $filetypes[$filetype] . '=' . $filename . '" method="post">';
|
||||
@ -151,13 +192,18 @@ if(isset($fichier)) {
|
||||
$filetitle = $resultat[0]['titre'];
|
||||
|
||||
echo '<div><label for="article-titre">Titre : </label><input type="text" name="article-titre" value="' . $resultat[0]['titre'] . '"></div>';
|
||||
echo '<div><label for="article-image">Couverture : </label><input type="text" name="article-image" value="' . $resultat[0]['image'] . '"></div>';
|
||||
echo '<div><textarea name="article-resume" placeholder="Résumé de l\'article (200 cacactères) ..." class="article-resume-input" maxlength="200">' . str_replace("<br />", "", $resultat[0]['resume']) . '</textarea></div>';
|
||||
}
|
||||
}
|
||||
echo "<div><h1>" . $filetitle . "</h1></div>";
|
||||
echo '<div><textarea name="page-content" placeholder="Contenu de l\'article (MarkDown) ...">' . str_replace("<br />", "", $contenu) . '</textarea></div>';
|
||||
echo '<div><input type="submit" value="Publier"></div></form>';
|
||||
if($resultat) {
|
||||
echo '<form action="?article=' . $_GET['article'] . '" method="post" enctype="multipart/form-data">';
|
||||
echo '<input type="file" name="banner">';
|
||||
echo '<input type="submit" value="Mettre à jour la Banière">';
|
||||
echo '</form></div>';
|
||||
}
|
||||
} else {
|
||||
echo "<div><div><h2>Pages</h2></div>";
|
||||
echo "<div>";
|
||||
|
Loading…
x
Reference in New Issue
Block a user