Add Item and Download of Images works
This commit is contained in:
56
add_item.php
Normal file
56
add_item.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
include_once('config/config.php');
|
||||
|
||||
$ItemTitle = $_POST['ItemTitle'];
|
||||
$ItemDescription = $_POST['ItemDescription'];
|
||||
$ItemPrice = $_POST['ItemPrice'];
|
||||
$ItemLink = $_POST['ItemLink'];
|
||||
$ItemImage = $_POST['ItemImage'];
|
||||
|
||||
|
||||
#--- check if the provided Image-Link is a real image:
|
||||
|
||||
$headers = get_headers($ItemImage, 1);
|
||||
|
||||
if (strpos($headers['Content-Type'], 'image/') !== false) {
|
||||
$imageLocalLink = 'data/images/' . uniqid() . '.' . pathinfo($ItemImage, PATHINFO_EXTENSION);
|
||||
echo "ImageLink: " . $imageLocalLink;
|
||||
file_put_contents($imageLocalLink, fopen($ItemImage, 'r'));
|
||||
} else {
|
||||
echo "Link is Not an Image";
|
||||
}
|
||||
|
||||
#---
|
||||
|
||||
$ItemPriceCents = $ItemPrice * 100;
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die('Connection failed: ' . $conn->connect_error);
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price) VALUES (?, ?, ?, ?, ?)');
|
||||
|
||||
if (false === $stmt) {
|
||||
die('prepare() failed: ' . htmlspecialchars($mysqli->error));
|
||||
}
|
||||
|
||||
$rc = $stmt->bind_param('ssssi', $ItemTitle, $ItemDescription, $imageLocalLink, $ItemImage, $ItemPriceCents);
|
||||
if (false === $rc) {
|
||||
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
|
||||
}
|
||||
|
||||
$rc = $stmt->execute();
|
||||
if (false === $rc) {
|
||||
die('execute() failed: ' . htmlspecialchars($stmt->error));
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
Reference in New Issue
Block a user