renamed file
This commit is contained in:
72
item.php
Normal file
72
item.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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'];
|
||||
$ListID = $_POST['ItemListID'];
|
||||
$nextPriority = 0;
|
||||
|
||||
#--- check if the provided Link is a valid URL
|
||||
|
||||
if (filter_var($ItemLink, FILTER_VALIDATE_URL) === FALSE) {
|
||||
die('Not a valid URL');
|
||||
}
|
||||
|
||||
#---
|
||||
|
||||
#--- check if the provided Image-Link is a real image:
|
||||
|
||||
$headers = array_change_key_case(get_headers($ItemImage, 1), CASE_LOWER); // make all keys LowerCase
|
||||
|
||||
if (strpos($headers['content-type'], 'image/') !== false) {
|
||||
$strippedimagepath = strtok($ItemImage, '?');
|
||||
$imageLocalLink = uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION);
|
||||
echo "ImageLink: " . $imageLocalLink;
|
||||
file_put_contents($imagedir . '/' . $imageLocalLink, fopen($strippedimagepath, 'r'));
|
||||
} else {
|
||||
echo "Link is Not an Image";
|
||||
}
|
||||
|
||||
#---
|
||||
|
||||
$ItemPriceCents = floatval(str_replace(',', '.', str_replace('.', '', $ItemPrice))) * 100;
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die('Connection failed: ' . $conn->connect_error);
|
||||
}
|
||||
|
||||
$stmt = 'SELECT MAX( priority ) AS maxprio FROM whishes WHERE whislist = ' . $ListID . ';';
|
||||
$result = $conn->query($stmt);
|
||||
|
||||
while ($row = mysqli_fetch_array($result)) {
|
||||
$nextPriority = $row['maxprio'] + 1;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price, whislist, priority) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
||||
|
||||
if (false === $stmt) {
|
||||
die('prepare() failed: ' . htmlspecialchars($conn->error));
|
||||
}
|
||||
|
||||
$rc = $stmt->bind_param('ssssiii', $ItemTitle, $ItemDescription, $ItemLink, $imageLocalLink, $ItemPriceCents, $ListID, $nextPriority);
|
||||
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