2022-07-21 14:53:04 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>UwU</title>
|
|
|
|
<link rel="stylesheet" href="css/master.css">
|
|
|
|
<link href="https://fonts.googleapis.com/css2?family=Rubik" rel="stylesheet">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php include('ui/header.php'); ?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// Attempt database connection
|
|
|
|
$conn = mysqli_connect("localhost", "uwu", "password", "swag");
|
|
|
|
// If connecton failed, notify user
|
|
|
|
if (!$conn) {
|
|
|
|
echo "<p class='alert fail'>Could not connect to database</p>";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div class="image-container">
|
|
|
|
<?php
|
|
|
|
// Get image ID
|
|
|
|
// Getting all image info from table
|
|
|
|
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
|
|
|
|
$image_results = mysqli_query($conn, $get_image);
|
|
|
|
$image = mysqli_fetch_assoc($image_results);
|
|
|
|
|
2022-07-21 22:14:56 +00:00
|
|
|
if ($image['imagename'] != "") {
|
|
|
|
$image_name = "images/".$image['imagename'];
|
|
|
|
$image_alt = $image['alt'];
|
|
|
|
}else{
|
|
|
|
$image_name = "assets/no_image.png";
|
|
|
|
$image_alt = "No image could be found, sowwy";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<img class='image' id='".$image['id']."' src='".$image_name."' alt='".$image_alt."'>";
|
2022-07-21 14:53:04 +00:00
|
|
|
|
|
|
|
if (!isset($_GET['id'])) {
|
|
|
|
echo "cannot obtain image";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="image-detail flex-down">
|
|
|
|
<?php
|
|
|
|
echo "<p>ID: ".$image['id']."</p>";
|
|
|
|
echo "<p>File Name: ".$image['imagename']."</p>";
|
|
|
|
echo "<p>Upload Date: ".$image['upload']."</p>";
|
2022-07-21 22:14:56 +00:00
|
|
|
echo "<p>Description: ".$image_alt."</p>";
|
2022-07-21 14:53:04 +00:00
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="danger-zone flex-down">
|
|
|
|
<h2>Danger zone</h2>
|
|
|
|
<?php
|
|
|
|
// Image hover details
|
2022-07-21 18:42:03 +00:00
|
|
|
echo "<form class='detail' method='POST' enctype='multipart/form-data'>";
|
|
|
|
echo "<button class='btn alert-low' type='submit' name='delete' value='".$image['id']."'>Delete image</button>";
|
2022-07-21 14:53:04 +00:00
|
|
|
echo "</form>";
|
|
|
|
|
|
|
|
// Check if query is set
|
2022-07-21 18:42:03 +00:00
|
|
|
if (isset($_POST['delete'])) {
|
2022-07-21 14:53:04 +00:00
|
|
|
// Try deleting image
|
2022-07-21 18:42:03 +00:00
|
|
|
if(unlink("images/".$image['imagename'])) {
|
2022-07-21 14:53:04 +00:00
|
|
|
// If deleted, delete from Table
|
2022-07-21 18:42:03 +00:00
|
|
|
$image_delete_request = "DELETE FROM swag_table WHERE id =".$image['id'];
|
|
|
|
$image_delete = mysqli_query($conn,$image_delete_request);
|
|
|
|
if ($image_delete) {
|
2022-07-21 14:53:04 +00:00
|
|
|
// Deleted image
|
2022-07-21 18:42:03 +00:00
|
|
|
header("Location:index.php?del=true&id=".$image['id']);
|
2022-07-21 14:53:04 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
// Could not delete from file
|
2022-07-21 18:42:03 +00:00
|
|
|
echo "<p class='alert alert-fail' id='deleted'>Error: Coult not delete image</p>";
|
2022-07-21 14:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php include('ui/footer.php'); ?>
|
|
|
|
</body>
|
|
|
|
</html>
|