mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2024-12-29 10:56:12 +00:00
Reformatting codew
This commit is contained in:
parent
19e945d1cd
commit
d6c9951233
|
@ -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);
|
||||
|
|
|
@ -42,3 +42,12 @@ nav hr {
|
|||
justify-content: space-around;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
.nav-hide {
|
||||
display: none;
|
||||
}
|
||||
.nav-links a .svg {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
|
35
edit.php
35
edit.php
|
@ -14,34 +14,46 @@
|
|||
include("ui/header.php");
|
||||
include("ui/conn.php");
|
||||
|
||||
// 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
|
||||
// Check if user owns image
|
||||
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);
|
||||
// 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()) {
|
||||
// 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 fuckywucky";
|
||||
$error = "Something went fuckywucky, please try later";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = "No description/alt, pls give";
|
||||
}
|
||||
} else {
|
||||
$error = "You do not have edit rights";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$error = "You must be logged in to edit images";
|
||||
//header("Location: https://superdupersecteteuploadtest.fluffybean.gay");
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="edit-root">
|
||||
|
@ -51,7 +63,6 @@
|
|||
<input class="btn alert-default space-bottom-large" type="text" name="alt" placeholder="Description/Alt for image">
|
||||
<?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>
|
||||
|
||||
<?php
|
||||
if (isset($error)) {
|
||||
echo "<p class='alert alert-low space-top'>".$error."</p>";
|
||||
|
|
12
image.php
12
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 "<p>Author: No author</p>";
|
||||
}
|
||||
|
||||
// Views
|
||||
//echo "<p>Views: ".$image['views']."</p>";
|
||||
|
||||
// Image ID
|
||||
echo "<p>ID: ".$image['id']."</p>";
|
||||
|
||||
|
@ -90,7 +100,7 @@
|
|||
echo "<p>File Name: ".$image['imagename']."</p>";
|
||||
|
||||
// Image Upload date
|
||||
echo "<p>Upload Date: ".$image['upload']."</p>";
|
||||
echo "<p>Last updated: ".$image['upload']." (+0)</p>";
|
||||
|
||||
// Image resolution
|
||||
list($width, $height) = getimagesize($image_path);
|
||||
|
|
|
@ -108,6 +108,7 @@
|
|||
echo "<p class='alert alert-high space-top'>".$success."</p>";
|
||||
}
|
||||
?>
|
||||
<a class='btn alert-default space-top-large' href='https://superdupersecteteuploadtest.fluffybean.gay/signup.php'><img class="svg" src="assets/icons/sign-in.svg">Need an account? Sign up!</a>
|
||||
</div>
|
||||
|
||||
<?php include("ui/footer.php"); ?>
|
||||
|
|
|
@ -129,7 +129,6 @@
|
|||
}
|
||||
?>
|
||||
</form>
|
||||
<a class='btn alert-default space-top-large' href='https://superdupersecteteuploadtest.fluffybean.gay/login.php'><img class="svg" src="assets/icons/sign-in.svg">Got an account? Login!</a>
|
||||
</div>
|
||||
|
||||
<?php include("ui/footer.php"); ?>
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
<h3>Fluffys Amazing Gallery!</h3>
|
||||
</div>
|
||||
<div class="nav-links flex-left">
|
||||
<a class="btn alert-default" href="https://superdupersecteteuploadtest.fluffybean.gay"><img class="svg" src="assets/icons/house.svg">Home</a>
|
||||
<a class="btn alert-default" href="https://superdupersecteteuploadtest.fluffybean.gay"><img class="svg" src="assets/icons/house.svg"><span class="nav-hide">Home</span></a>
|
||||
<hr>
|
||||
<?php
|
||||
if (isset($_SESSION["username"])) {
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/upload.php'><img class='svg' src='assets/icons/upload.svg'>Upload</a>";
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/upload.php'><img class='svg' src='assets/icons/upload.svg'><span class='nav-hide'>Upload</span></a>";
|
||||
echo "<hr>";
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/account.php'><img class='svg' src='assets/icons/user-circle.svg'>".$_SESSION["username"]."</a>";
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/account.php'><img class='svg' src='assets/icons/user-circle.svg'><span class='nav-hide'>".$_SESSION["username"]."</span></a>";
|
||||
} else {
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/signup.php'><img class='svg' src='assets/icons/user-circle-plus.svg'>Sign Up</a>";
|
||||
echo "<a class='btn alert-default' href='https://superdupersecteteuploadtest.fluffybean.gay/login.php'><img class='svg' src='assets/icons/user-circle-plus.svg'><span class='nav-hide'>Login</span></a>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
|
46
upload.php
46
upload.php
|
@ -16,51 +16,52 @@
|
|||
|
||||
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;
|
||||
|
||||
// Check if errors occured
|
||||
if (empty($error)) {
|
||||
// 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);
|
||||
$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
|
||||
// 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);
|
||||
// Get image format
|
||||
$image_format = $image_thumbnail->getImageFormat();
|
||||
// If image is gif
|
||||
// If image is GIF
|
||||
if ($image_format == 'GIF') {
|
||||
$image_thumbnail = $image_thumbnail->coalesceImages();
|
||||
}
|
||||
// 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 {
|
||||
$error = "Something went fuckywucky, please try later";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No image present
|
||||
$error = "No file lol";
|
||||
|
@ -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 @@
|
|||
<input class="btn alert-default space-bottom-large" type="text" name="alt" placeholder="Description/Alt for image">
|
||||
<button class="btn alert-default" type="submit" name="upload"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
if (isset($error)) {
|
||||
echo "<p class='alert alert-low space-top'>".$error."</p>";
|
||||
|
|
Loading…
Reference in a new issue