Files
homepage/admin/inhalte/fotos/bilder/add.php

58 lines
2.1 KiB
PHP
Raw Blame History

<h3>Neues Bild hinzufügen</h3>
<?php
if (!isset($_POST['Speichern'])) {
?>
<form action="index.php?section=fotos&t=bilder" method="post" enctype="multipart/form-data">
<label>Foto auswählen</label>
<input type="hidden" name="add" value="speichern"/>
<input type="file" name="Foto"/>
<br/>
<label>Bildüberschrift</label>
<textarea name="Text" cols="90" rows="10"></textarea>
<br/>
<input type="submit" name="Speichern" value="Speichern"/>
</form>
<?php
} else {
if ('' != $_FILES['Foto']['name']) {
$Text = $db->real_escape_string($_POST['Text']);
$sql1 = 'INSERT INTO bilder (ID, Head) VALUES (NULL, "' . $Text . '");';
$stmt1 = $db->prepare($sql1);
if (!$stmt1) {
die ('Es konnte kein SQL-Query vorbereitet werden: ' . $db->error);
}
if (!$stmt1->execute()) {
die ('Query konnte nicht ausgef<65>hrt werden: ' . $stmt1->error);
}
$sql2 = 'SELECT last_insert_id()';
$result2 = $db->query($sql2);
$last = $result2->fetch_assoc();
$id = $last['last_insert_id()'];
$uploaddir = __DIR__ . '/../../../../public/img/umgebung/bilder/';
$uploadfile = $uploaddir . $_FILES['Foto']['name'];
$test = move_uploaded_file($_FILES['Foto']['tmp_name'], $uploadfile);
$src = imagecreatefromjpeg($uploadfile);
list($width, $height) = getimagesize($uploadfile);
if ($height > $width) {
$newheight = 460;
$newwidth = ($width / $height) * 460;
} else {
$newwidth = 460;
$newheight = ($height / $width) * 460;
}
$tmp = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$filename = $uploaddir . $id . ".jpg";
imagejpeg($tmp, $filename, 80);
imagedestroy($src);
imagedestroy($tmp);
unlink($uploaddir . $_FILES['Foto']['name']);
}
echo '<a href="index.php?section=fotos&t=bilder">Zurück zur Übersicht</a>';
}