mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-05-28 22:33:11 +00:00
Prepared sql for pain
This commit is contained in:
parent
2c6beefa43
commit
08d15c9253
8 changed files with 65 additions and 63 deletions
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
.image-container {
|
.image-container {
|
||||||
height: 40vh;
|
height: 35vh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-description {
|
.image-description {
|
||||||
margin: 0 0 2rem; padding: 0.5rem;;
|
margin: 0 0 2rem; padding: 0.5rem;
|
||||||
|
|
||||||
background-color: var(--bg); color: var(--fg);
|
background-color: var(--bg); color: var(--fg);
|
||||||
|
|
||||||
|
@ -42,10 +42,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-detail {
|
.image-detail {
|
||||||
margin: 0 0 2rem; padding: 0.5rem;;
|
margin: 0 0 2rem; padding: 0.5rem;
|
||||||
|
|
||||||
background-color: var(--bg); color: var(--fg);
|
background-color: var(--bg); color: var(--fg);
|
||||||
|
|
||||||
|
word-wrap: break-word;
|
||||||
|
|
||||||
border: 0.2rem solid var(--green);
|
border: 0.2rem solid var(--green);
|
||||||
outline: 0.5rem solid var(--bg);
|
outline: 0.5rem solid var(--bg);
|
||||||
|
|
||||||
|
@ -54,7 +56,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.danger-zone {
|
.danger-zone {
|
||||||
margin: 0 0 2rem; padding: 0.5rem;;
|
margin: 0 0 2rem; padding: 0.5rem;
|
||||||
|
|
||||||
background-color: var(--bg); color: var(--fg);
|
background-color: var(--bg); color: var(--fg);
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ form * {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|
||||||
text-decoration: underline;
|
text-decoration: none;
|
||||||
|
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: var(--rad);
|
border-radius: var(--rad);
|
||||||
|
@ -138,7 +138,7 @@ a.btn {
|
||||||
|
|
||||||
.svg {
|
.svg {
|
||||||
margin: 0 0.2rem 0.1rem 0;
|
margin: 0 0.2rem 0.1rem 0;
|
||||||
width: 18px; height: 18px;
|
width: 19px; height: 18px;
|
||||||
|
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ nav h3 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
nav hr {
|
nav hr {
|
||||||
margin: 0.5rem 0; padding: 0;
|
margin: 0.5rem 0.2rem; padding: 0;
|
||||||
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
28
edit.php
28
edit.php
|
@ -10,18 +10,16 @@
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php include("ui/header.php"); ?>
|
||||||
include("ui/header.php");
|
|
||||||
$id = $_GET["id"];
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="edit-root">
|
<div class="edit-root">
|
||||||
<h2>Modify Information</h2>
|
<h2>Modify Information</h2>
|
||||||
<p class="space-below">Make sure that the id of the image is correct!</p>
|
<p class="space-below">This is a dangerous place to step foot into... tread carefully.</p>
|
||||||
<form class="flex-down between" method="POST" action="edit.php" enctype="multipart/form-data">
|
<form class="flex-down between" method="POST" action="edit.php" enctype="multipart/form-data">
|
||||||
<input class="btn alert-default space-bottom" type="text" name="alt" placeholder="Description/Alt for image">
|
<input class="btn alert-default space-bottom" type="text" name="alt" placeholder="Description/Alt for image">
|
||||||
<?php echo "<button class='btn alert-default' type='submit' name='update' value=".$id.">Update information</button>"; ?>
|
<?php echo "<button class='btn alert-default' type='submit' name='id' value=".$_GET["id"]."><img class='svg' src='assets/icons/edit.svg'>Update information</button>"; ?>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if ($_GET["r"] == "success") {
|
if ($_GET["r"] == "success") {
|
||||||
// Info updated
|
// Info updated
|
||||||
|
@ -32,24 +30,27 @@
|
||||||
} elseif ($_GET["r"] == "noinfo") {
|
} elseif ($_GET["r"] == "noinfo") {
|
||||||
// No info was present
|
// No info was present
|
||||||
echo "<p class='alert alert-default space-top'>No description/alt, pls give</p>";
|
echo "<p class='alert alert-default space-top'>No description/alt, pls give</p>";
|
||||||
} else {
|
|
||||||
// echo "<p class='alert alert-default'>Please enter information</p>";
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php include("ui/conn.php");
|
<?php
|
||||||
|
include("ui/conn.php");
|
||||||
|
|
||||||
if (isset($_POST['update'])) {
|
if (isset($_POST['id'])) {
|
||||||
if (empty($_POST['alt'])) {
|
if (empty($_POST['alt'])) {
|
||||||
header("Location:edit.php?r=noinfo");
|
header("Location:edit.php?r=noinfo");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$sql = "UPDATE swag_table SET alt='".$_POST['alt']."' WHERE id=".$_POST['update'];
|
$sql = $conn->prepare("UPDATE swag_table SET alt=? WHERE id=?");
|
||||||
|
$sql->bind_param("si", $alt, $id);
|
||||||
|
|
||||||
if (mysqli_query($conn, $sql)) {
|
$alt = $_POST['alt'];
|
||||||
|
$id = $_POST['id'];
|
||||||
|
|
||||||
|
if ($sql->execute()) {
|
||||||
//header("Location:edit.php?r=success");
|
//header("Location:edit.php?r=success");
|
||||||
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['update']."&update=success");
|
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['id']."&update=success");
|
||||||
} else {
|
} else {
|
||||||
header("Location:edit.php?r=fail");
|
header("Location:edit.php?r=fail");
|
||||||
}
|
}
|
||||||
|
@ -57,7 +58,6 @@
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<?php include("ui/footer.php"); ?>
|
<?php include("ui/footer.php"); ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
25
image.php
25
image.php
|
@ -14,32 +14,38 @@
|
||||||
include("ui/header.php");
|
include("ui/header.php");
|
||||||
include_once("ui/conn.php");
|
include_once("ui/conn.php");
|
||||||
|
|
||||||
|
|
||||||
|
// Update toast
|
||||||
|
if ($_GET["update"] == "success") {
|
||||||
|
echo "<p class='alert alert-high space-bottom'>Information updated</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get image ID
|
// Get image ID
|
||||||
// Getting all image info from table
|
// Getting all image info from table
|
||||||
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
|
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
|
||||||
$image_results = mysqli_query($conn, $get_image);
|
$image_results = mysqli_query($conn, $get_image);
|
||||||
$image = mysqli_fetch_assoc($image_results);
|
$image = mysqli_fetch_assoc($image_results);
|
||||||
|
|
||||||
// Image has been modified successfully
|
|
||||||
if ($_GET["update"] == "success") {
|
|
||||||
echo "<p class='alert alert-high space-bottom'>Information updated</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if ID of image in URL
|
// Check if ID of image in URL
|
||||||
if (!isset($_GET['id'])) {
|
if (!isset($_GET['id'])) {
|
||||||
// No ID
|
// No ID toast
|
||||||
echo "<p class='alert alert-low space-bottom'>No ID present</p>";
|
echo "<p class='alert alert-low space-bottom'>No ID present</p>";
|
||||||
|
|
||||||
// Replacement "no image" image and description
|
// Replacement "no image" image and description
|
||||||
$image_path = "assets/no_image.png";
|
$image_path = "assets/no_image.png";
|
||||||
$image_alt = "No image could be found, sowwy";
|
$image_alt = "No image could be found, sowwy";
|
||||||
|
|
||||||
} elseif (empty($image['imagename'])) {
|
} elseif (empty($image['imagename'])) {
|
||||||
// proposed ID not avalible
|
// ID not avalible toast
|
||||||
echo "<p class='alert alert-low'>Could not find image with ID: ".$_GET['id']."</p>";
|
echo "<p class='alert alert-low'>Could not find image with ID: ".$_GET['id']."</p>";
|
||||||
|
|
||||||
// Replacement "no image" image and description
|
// Replacement "no image" image and description
|
||||||
$image_path = "assets/no_image.png";
|
$image_path = "assets/no_image.png";
|
||||||
$image_alt = "No image could be found, sowwy";
|
$image_alt = "No image could be found, sowwy";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Image avalible
|
// Display image
|
||||||
$image_path = "images/".$image['imagename'];
|
$image_path = "images/".$image['imagename'];
|
||||||
$image_alt = $image['alt'];
|
$image_alt = $image['alt'];
|
||||||
}
|
}
|
||||||
|
@ -95,10 +101,11 @@
|
||||||
// Check if query is set
|
// Check if query is set
|
||||||
if (isset($_POST['delete'])) {
|
if (isset($_POST['delete'])) {
|
||||||
// Try deleting image
|
// Try deleting image
|
||||||
if(unlink("images/".$image['imagename'])) {
|
if(unlink("images/".$image['imagename']) && unlink("images/thumbnails/".$image['imagename'])) {
|
||||||
// If deleted, delete from Table
|
// If deleted, delete from Table
|
||||||
$image_delete_request = "DELETE FROM swag_table WHERE id =".$image['id'];
|
$image_delete_request = "DELETE FROM swag_table WHERE id =".$image['id'];
|
||||||
$image_delete = mysqli_query($conn,$image_delete_request);
|
$image_delete = mysqli_query($conn,$image_delete_request);
|
||||||
|
|
||||||
if ($image_delete) {
|
if ($image_delete) {
|
||||||
// Deleted image
|
// Deleted image
|
||||||
header("Location:index.php?del=true&id=".$image['id']);
|
header("Location:index.php?del=true&id=".$image['id']);
|
||||||
|
|
37
index.php
37
index.php
|
@ -10,9 +10,10 @@
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php include("ui/header.php"); ?>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
include("ui/header.php");
|
||||||
|
|
||||||
|
// Deletion toast
|
||||||
if ($_GET["del"] == "true") {
|
if ($_GET["del"] == "true") {
|
||||||
echo "<p class='alert alert-high space-bottom'>Successfully deleted image: ".$_GET['id']."</p>";
|
echo "<p class='alert alert-high space-bottom'>Successfully deleted image: ".$_GET['id']."</p>";
|
||||||
}
|
}
|
||||||
|
@ -23,30 +24,24 @@
|
||||||
<p>Fluffy's test website on uploading images to a database!</p>
|
<p>Fluffy's test website on uploading images to a database!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
|
||||||
include_once("ui/conn.php");
|
|
||||||
|
|
||||||
|
|
||||||
// My terrible workaround for not being able to show deletion status up here
|
|
||||||
if (isset($_GET['d'])) {
|
|
||||||
echo "<p class='alert default'>Image ".$_GET['d']." has been modified, <a href='#deleted'>view status here</a></p>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<div class="gallery-root flex-left">
|
<div class="gallery-root flex-left">
|
||||||
<?php
|
<?php
|
||||||
// Reading images from table
|
include_once("ui/conn.php");
|
||||||
$img = mysqli_query($conn, "SELECT * FROM swag_table");
|
|
||||||
while ($row = mysqli_fetch_array($img)) {
|
|
||||||
// Getting thumbnail
|
|
||||||
if (file_exists("images/thumbnails/".$row['imagename'])) {
|
|
||||||
$image_path = "images/thumbnails/".$row['imagename'];
|
|
||||||
} else {
|
|
||||||
$image_path = "images/".$row['imagename'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Reading images from table
|
||||||
|
$image_request = mysqli_query($conn, "SELECT * FROM swag_table");
|
||||||
|
|
||||||
|
while ($image = mysqli_fetch_array($image_request)) {
|
||||||
|
// Getting thumbnail
|
||||||
|
if (file_exists("images/thumbnails/".$image['imagename'])) {
|
||||||
|
$image_path = "images/thumbnails/".$image['imagename'];
|
||||||
|
} else {
|
||||||
|
$image_path = "images/".$image['imagename'];
|
||||||
|
}
|
||||||
|
|
||||||
// Image loading
|
// Image loading
|
||||||
echo "<div class='gallery-item'>";
|
echo "<div class='gallery-item'>";
|
||||||
echo "<a href='https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$row['id']."'><img class='gallery-image' loading='lazy' src='".$image_path."' id='".$row['id']."'></a>";
|
echo "<a href='https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$image['id']."'><img class='gallery-image' loading='lazy' src='".$image_path."' id='".$image['id']."'></a>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Attempt database connection
|
// Attempt database connection
|
||||||
$conn = mysqli_connect("localhost", "uwu", "password", "swag");
|
$conn = mysqli_connect("localhost", "uwu", "password", "swag");
|
||||||
// If connecton failed, notify user
|
// If connecton failed, notify user
|
||||||
if (!$conn) {
|
if ($conn->connect_error) {
|
||||||
echo "<p class='alert alert-low'>Could not connect to database</p>";
|
echo "<p class='alert alert-low'>Could not connect to database</p>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
20
upload.php
20
upload.php
|
@ -17,8 +17,9 @@
|
||||||
<form class="flex-down between" method="POST" action="upload.php" enctype="multipart/form-data">
|
<form class="flex-down between" method="POST" action="upload.php" enctype="multipart/form-data">
|
||||||
<input class="btn alert-default space-bottom" type="file" name="image" placeholder="select image UwU">
|
<input class="btn alert-default space-bottom" type="file" name="image" placeholder="select image UwU">
|
||||||
<input class="btn alert-default space-bottom" type="text" name="alt" placeholder="Description/Alt for image">
|
<input class="btn alert-default space-bottom" type="text" name="alt" placeholder="Description/Alt for image">
|
||||||
<button class="btn alert-default" type="submit" name="upload">Upload Image</button>
|
<button class="btn alert-default" type="submit" name="upload"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if ($_GET["r"] == "success") {
|
if ($_GET["r"] == "success") {
|
||||||
// Image uploaded
|
// Image uploaded
|
||||||
|
@ -29,8 +30,6 @@
|
||||||
} elseif ($_GET["r"] == "nofile") {
|
} elseif ($_GET["r"] == "nofile") {
|
||||||
// No file was present
|
// No file was present
|
||||||
echo "<p class='alert alert-default space-top'>No file lol</p>";
|
echo "<p class='alert alert-default space-top'>No file lol</p>";
|
||||||
} else {
|
|
||||||
// echo "<p class='alert alert-default'>Select an image to upload</p>";
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,10 +37,9 @@
|
||||||
<?php
|
<?php
|
||||||
include_once("ui/conn.php");
|
include_once("ui/conn.php");
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST['upload'])) {
|
if (isset($_POST['upload'])) {
|
||||||
// Get image name
|
// Get image name
|
||||||
$get_image_name = $_FILES['image']['name'];
|
$image_name = $_FILES['image']['name'];
|
||||||
|
|
||||||
// Get alt text
|
// Get alt text
|
||||||
if (empty($_POST['alt'])) {
|
if (empty($_POST['alt'])) {
|
||||||
|
@ -50,18 +48,18 @@
|
||||||
$get_alt_text = $_POST['alt'];
|
$get_alt_text = $_POST['alt'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If image present, continue
|
// If image present, continue
|
||||||
if (!empty($get_image_name)) {
|
if (!empty($image_name)) {
|
||||||
// Set file path for image upload
|
// Set file path for image upload
|
||||||
$image_basename = basename($get_image_name);
|
$image_basename = basename($image_name);
|
||||||
$image_path = "images/".$image_basename;
|
$image_path = "images/".$image_basename;
|
||||||
$sql = "INSERT INTO swag_table (imagename, alt) VALUES ('$get_image_name','$get_alt_text')";
|
|
||||||
|
|
||||||
|
// Prepare sql for destruction and filtering the sus
|
||||||
|
$sql = $conn->prepare("INSERT INTO swag_table (imagename, alt) VALUES (?, ?)");
|
||||||
|
$sql->bind_param("ss", $image_name, $get_alt_text);
|
||||||
|
|
||||||
// Uploading image to Table
|
// Uploading image to Table
|
||||||
mysqli_query($conn, $sql);
|
$sql->execute();
|
||||||
|
|
||||||
|
|
||||||
// Checking if image uploaded
|
// Checking if image uploaded
|
||||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue