diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-13 16:06:42 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-13 16:06:42 +0200 |
commit | 4a6320cc87541dd9d997301cf138644e4564445c (patch) | |
tree | cb5b609fa8d28ad9ab21dc896b620fd14cdbc3db | |
parent | ed0594f8f73c6eee8c6eca6ecf6208952ea26cdc (diff) |
image upload werkt
-rw-r--r-- | public/admin-product.php | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/public/admin-product.php b/public/admin-product.php index a760ebe..9431cb2 100644 --- a/public/admin-product.php +++ b/public/admin-product.php @@ -11,18 +11,28 @@ do { if ($_SERVER['REQUEST_METHOD'] !== 'POST') break; $name = $_POST['name']; $description = $_POST['description']; - $image = $_POST['img']; $price = $_POST['price']; $category = $_POST['category']; - $image = true; + $img = !!$_FILES['img']; if (!$name) break; if (!$description) break; if (!$price) break; if (!$category) break; $statement = $cursor->prepare("insert into webs.product (`name`, `description`, `price`, `category`, `image`) values (?, ?, ?, ?, ?)"); - $statement->bind_param("ssdii", $name, $description, $price, $category, $image); + $statement->bind_param("ssdii", $name, $description, $price, $category, $img); $statement->execute(); + + $data = file_get_contents($_FILES["img"]["tmp_name"]); + $image = imagecreatefromstring($data); + if (!$image) break; + + $full_path = "img/product/$new_id-full.jpg"; + imagejpeg($image, $full_path); + + $thumb = imagescale($image, 250); + $thumb_path = "img/product/$new_id-thumb.jpg"; + imagejpeg($thumb, $thumb_path); } while (false); ?> <html> @@ -35,7 +45,7 @@ do { <?php include 'navbar.php' ?> <div class="main limwidth"> <h2>product toevoegen</h2> - <form action="/admin-product.php" method="post"> + <form action="/admin-product.php" method="post" enctype="multipart/form-data"> <label for="id">ID (automatisch)</label> <input id="id" type="text" disabled value="<?php echo $new_id; ?>"> <label for="name">Naam</label> |