diff --git a/add_item.php b/add_item.php index f0547fb..032eeef 100644 --- a/add_item.php +++ b/add_item.php @@ -10,6 +10,13 @@ $ItemPrice = $_POST['ItemPrice']; $ItemLink = $_POST['ItemLink']; $ItemImage = $_POST['ItemImage']; +#--- 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: @@ -17,7 +24,7 @@ $headers = array_change_key_case(get_headers($ItemImage, 1), CASE_LOWER); if (strpos($headers['content-type'], 'image/') !== false) { $strippedimagepath = strtok($ItemImage, '?'); - $imageLocalLink = 'data/images/' . uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION); + $imageLocalLink = $imagedir . '/' . uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION); echo "ImageLink: " . $imageLocalLink; file_put_contents($imageLocalLink, fopen($strippedimagepath, 'r')); } else { diff --git a/config/config.php b/config/config.php index b64b653..a659a69 100644 --- a/config/config.php +++ b/config/config.php @@ -4,5 +4,6 @@ $servername = 'localhost'; $username = 'wishlist'; $db = 'wishlist'; $password = 'R!6CIb-KxM96EC]6'; +$imagedir = 'data/images'; ?> \ No newline at end of file diff --git a/include/delete_unused.php b/include/delete_unused.php new file mode 100644 index 0000000..1ec6b81 --- /dev/null +++ b/include/delete_unused.php @@ -0,0 +1,32 @@ +connect_error) + die('Connection failed: ' . $conn->connect_error); + +$sql = 'SELECT image FROM whishes'; +$result = $conn->query($sql); + + if ($result !== false && $result->num_rows > 0) + { + if ($rows = $result->fetch_all()) + { + foreach ($dir as $fileinfo) { + if (!$fileinfo->isDot()) { + $filename = $fileinfo->getFilename(); + + if (!in_array($filename, $rows)) + { + $deletepath = '../' . $imagedir . '/' . $filename; + unset($deletepath); + } + } + } + } + } + +$conn->close(); \ No newline at end of file diff --git a/include/listgenerator.php b/include/listgenerator.php index fe0f9c3..90dee25 100644 --- a/include/listgenerator.php +++ b/include/listgenerator.php @@ -4,7 +4,7 @@ include 'config/config.php'; function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemPrice, $ItemComment, $ItemReserved, $ItemDate) { - global $loggedin; + global $loggedin, $imagedir; $formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY); @@ -18,7 +18,7 @@ function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemP
' . $ItemComment . '
Diese Liste gibt es nicht mehr
+