From d6c9951233b06750d76da5e5f004a9119eaedb30 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Tue, 26 Jul 2022 12:33:28 +0100 Subject: [PATCH] Reformatting codew --- css/gallery.css | 2 +- css/nav.css | 9 ++++++ edit.php | 53 +++++++++++++++++++++-------------- image.php | 12 +++++++- login.php | 1 + signup.php | 1 - ui/header.php | 8 +++--- upload.php | 74 ++++++++++++++++++++++++------------------------- 8 files changed, 95 insertions(+), 65 deletions(-) diff --git a/css/gallery.css b/css/gallery.css index cabb3ce..273f078 100644 --- a/css/gallery.css +++ b/css/gallery.css @@ -21,7 +21,7 @@ margin: 0.5rem; padding: 0; /*max-width: 232.5px; max-height: 232.5px;*/ - height: auto; max-width: 315px; + height: auto; max-width: 350px; background-color: var(--bg-2); border-radius: var(--rad); diff --git a/css/nav.css b/css/nav.css index 216f05e..a879e23 100644 --- a/css/nav.css +++ b/css/nav.css @@ -42,3 +42,12 @@ nav hr { justify-content: space-around; } } + +@media (max-width: 400px) { + .nav-hide { + display: none; + } + .nav-links a .svg { + margin: 0; + } +} diff --git a/edit.php b/edit.php index 309666b..625fa45 100644 --- a/edit.php +++ b/edit.php @@ -14,34 +14,46 @@ include("ui/header.php"); include("ui/conn.php"); - if (isset($_POST['id'])) { - // Getting all image info from table - $get_image = "SELECT * FROM swag_table WHERE id = ".$_POST['id']; - $image_results = mysqli_query($conn, $get_image); - $image = mysqli_fetch_assoc($image_results); + // Check if user is logged in + if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) { + // Get post ID from button + if (isset($_POST['id'])) { + // Getting all image info from table + $get_image = "SELECT * FROM swag_table WHERE id = ".$_POST['id']; + $image_results = mysqli_query($conn, $get_image); + $image = mysqli_fetch_assoc($image_results); - // Checking if user has edit rights - if (isset($_SESSION['id']) && $image['author'] == $_SESSION['id'] || $_SESSION['id'] == 1) { - if (isset($_POST['alt'])) { - $sql = $conn->prepare("UPDATE swag_table SET alt=? WHERE id=?"); - $sql->bind_param("si", $alt, $id); + // Check if user owns image + if (isset($_SESSION['id']) && $image['author'] == $_SESSION['id'] || $_SESSION['id'] == 1) { + // If no errors + if (empty($error)) { + // getting ready forSQL asky asky + $sql = "UPDATE swag_table SET alt=? WHERE id=?"; - $alt = $_POST['alt']; - $id = $_POST['id']; + // Checking if databse is doing ok + if ($stmt = mysqli_prepare($conn, $sql)) { + mysqli_stmt_bind_param($stmt, "si", $param_alt, $param_id); - if ($sql->execute()) { - header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['id']."&update=success"); - } else { - $error = "Something fuckywucky"; + // Setting parameters + $param_alt = $_POST['alt']; + $param_id = $_POST['id']; + + // Attempt to execute the prepared statement + if (mysqli_stmt_execute($stmt)) { + header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['id']."&update=success"); + } else { + $error = "Something went fuckywucky, please try later"; + } + } } } else { - $error = "No description/alt, pls give"; + $error = "You do not have edit rights"; } - } else { - $error = "You do not have edit rights"; } + } else { + $error = "You must be logged in to edit images"; + //header("Location: https://superdupersecteteuploadtest.fluffybean.gay"); } - ?>
@@ -51,7 +63,6 @@ Update information"; ?> - ".$error."

"; diff --git a/image.php b/image.php index 02be4db..6bc1761 100644 --- a/image.php +++ b/image.php @@ -53,6 +53,13 @@ // Display image $image_path = "images/".$image['imagename']; $image_alt = $image['alt']; + + // Add image view + if (empty($image['views'])) { + //$conn->query("UPDATE swag_table SET views=1 WHERE id=".$image['id']); + } else { + //$conn->query("UPDATE swag_table SET views=views+1 WHERE id=".$image['id']); + } } ?> @@ -83,6 +90,9 @@ echo "

Author: No author

"; } + // Views + //echo "

Views: ".$image['views']."

"; + // Image ID echo "

ID: ".$image['id']."

"; @@ -90,7 +100,7 @@ echo "

File Name: ".$image['imagename']."

"; // Image Upload date - echo "

Upload Date: ".$image['upload']."

"; + echo "

Last updated: ".$image['upload']." (+0)

"; // Image resolution list($width, $height) = getimagesize($image_path); diff --git a/login.php b/login.php index 9606b64..8e106b1 100644 --- a/login.php +++ b/login.php @@ -108,6 +108,7 @@ echo "

".$success."

"; } ?> + Need an account? Sign up!
diff --git a/signup.php b/signup.php index eb980c1..0ee14a6 100644 --- a/signup.php +++ b/signup.php @@ -129,7 +129,6 @@ } ?> - Got an account? Login! diff --git a/ui/header.php b/ui/header.php index da74682..a30fc80 100644 --- a/ui/header.php +++ b/ui/header.php @@ -5,15 +5,15 @@

Fluffys Amazing Gallery!

diff --git a/upload.php b/upload.php index 272b296..bfa29ee 100644 --- a/upload.php +++ b/upload.php @@ -16,50 +16,51 @@ if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) { if (isset($_POST['upload'])) { - // Get image name + // Setting image up for upload $image_name = $_FILES['image']['name']; - - // Get alt text - if (empty($_POST['alt'])) { - $get_alt_text = "No description provided"; - } else { - $get_alt_text = $_POST['alt']; - } - - // If image present, continue - if (!empty($image_name)) { + if (isset($image_name)) { // Set file path for image upload $image_basename = basename($image_name); $image_path = "images/".$image_basename; - // Prepare sql for destruction and filtering the sus - $sql = $conn->prepare("INSERT INTO swag_table (imagename, alt, author) VALUES (?, ?, ?)"); - $sql->bind_param("sss", $image_name, $get_alt_text, $user_id); + // Check if errors occured + if (empty($error)) { + // Prepare sql for destruction and filtering the sus + $sql = "INSERT INTO swag_table (imagename, alt, author) VALUES (?, ?, ?)"; - $user_id = $_SESSION["id"]; + // Can contact database? + if ($stmt = mysqli_prepare($conn, $sql)) { + // Bind the smelly smelly + mysqli_stmt_bind_param($stmt, "sss", $param_image_name, $param_alt_text, $param_user_id); - // Uploading image to Table - $sql->execute(); + // Setting up parameters + $param_image_name = $image_name; + $param_alt_text = $_POST['alt']; + $param_user_id = $_SESSION["id"]; - // Checking if image uploaded - if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) { - // Make thumbnail - $image_thumbnail = new Imagick($image_path); - // Get image format - $image_format = $image_thumbnail->getImageFormat(); - // If image is gif - if ($image_format == 'GIF') { - $image_thumbnail = $image_thumbnail->coalesceImages(); + // Attempt to execute the prepared statement + if (mysqli_stmt_execute($stmt)) { + // Move files onto server + if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) { + // Make thumbnail + $image_thumbnail = new Imagick($image_path); + $image_format = $image_thumbnail->getImageFormat(); + // If image is GIF + if ($image_format == 'GIF') { + $image_thumbnail = $image_thumbnail->coalesceImages(); + } + // Resize image + $image_thumbnail->resizeImage(300,null,null,1,null); + $image_thumbnail->writeImage("images/thumbnails/".$image_basename); + + $success = "Your Image uploaded successfully!"; + } else { + $error = "F, Upload failed"; + } + } else { + $error = "Something went fuckywucky, please try later"; + } } - // Resize image - $image_thumbnail->resizeImage(300,null,null,1,null); - // Save image - $image_thumbnail->writeImage("images/thumbnails/".$image_basename); - - $success = "Your Image uploaded successfully!"; - } else { - // Could not move images to folder - $error = "F, Upload failed"; } } else { // No image present @@ -68,7 +69,7 @@ } } else { $error = "You must be logged in to upload images"; - header("Location: https://superdupersecteteuploadtest.fluffybean.gay"); + //header("Location: https://superdupersecteteuploadtest.fluffybean.gay"); } ?> @@ -80,7 +81,6 @@ - ".$error."

";