mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-01-29 17:28:27 +00:00
nothing ever works for me
This commit is contained in:
parent
9ff82d7e85
commit
7c13b6478d
82
app/image/upload_image.php
Normal file
82
app/image/upload_image.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/*
|
||||
|-------------------------------------------------------------
|
||||
| Uploading Images
|
||||
|-------------------------------------------------------------
|
||||
| gwa gwa
|
||||
|-------------------------------------------------------------
|
||||
*/
|
||||
session_start();
|
||||
// Include server connection
|
||||
include "../server/conn.php";
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
// Root paths
|
||||
$dir = "images/";
|
||||
$thumb_dir = $dir."thumbnails/";
|
||||
|
||||
// File paths
|
||||
$image_basename = basename($_FILES['image']['name']);
|
||||
$image_path = $dir.$image_basename;
|
||||
$file_type = pathinfo($image_path,PATHINFO_EXTENSION);
|
||||
|
||||
// Allowed file types
|
||||
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
|
||||
if (in_array($file_type, $allowed_types)) {
|
||||
// Move file to server
|
||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
||||
// Attempt making a thumbnail
|
||||
try {
|
||||
$image_thumbnail = new Imagick($image_path);
|
||||
$image_thumbnail->resizeImage(300,null,null,1,null);
|
||||
$image_thumbnail->writeImage($thumb_dir.$image_basename);
|
||||
} catch (Exception $e) {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Gwha!', 'We hit a small roadbump during making of the thumbail. We will continue anyway!', 'var(--black)', '<?php echo $root_dir; ?>assets/icons/bug.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Prepare sql for destruction and filtering the sus
|
||||
$sql = "INSERT INTO swag_table (imagename, alt, author) VALUES (?, ?, ?)";
|
||||
|
||||
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);
|
||||
|
||||
// Setting up parameters
|
||||
$param_image_name = $_FILES['image']['name'];
|
||||
$param_alt_text = $_POST['alt'];
|
||||
$param_user_id = $_SESSION['id'];
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd(':3', 'Your Image uploaded successfully!', 'var(--green)', '<?php echo $root_dir; ?>assets/icons/check.svg');
|
||||
</script>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd(':c', 'Something went fuckywucky, please try later', 'var(--red)', '<?php echo $root_dir; ?>assets/icons/cross.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Hmmff', 'Something happened when moving the file to the server. This may just been a 1-off so try again', 'var(--red)', '<?php echo $root_dir; ?>assets/icons/bug.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Woopsie', 'The file type you are trying to upload is not supported. Supported files include: JPEG, JPG, PNG and WEBP', 'var(--red)', '<?php echo $root_dir; ?>assets/icons/cross.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
1
assets/icons/bug.svg
Normal file
1
assets/icons/bug.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" fill="#e8e3e3" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><circle cx="156" cy="92" r="12"></circle><circle cx="100" cy="92" r="12"></circle><line x1="128" y1="128" x2="128" y2="224" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><line x1="244" y1="128" x2="12" y2="128" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><path d="M208,144a80,80,0,0,1-160,0V112a80,80,0,0,1,160,0Z" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></path><line x1="231.9" y1="188" x2="203.2" y2="171.4" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><line x1="231.9" y1="68" x2="203.2" y2="84.6" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><line x1="24.1" y1="68" x2="52.8" y2="84.6" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><line x1="24.1" y1="188" x2="52.8" y2="171.4" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line></svg>
|
After Width: | Height: | Size: 1.2 KiB |
10
image.php
10
image.php
|
@ -205,8 +205,6 @@
|
|||
<div class='danger-zone flex-down default-window'>
|
||||
<h2>Danger zone</h2>
|
||||
|
||||
<script id="conformationMessage"></script>
|
||||
|
||||
<!--
|
||||
|-------------------------------------------------------------
|
||||
| Delete
|
||||
|
@ -228,7 +226,7 @@
|
|||
$("#deleteConfirm").submit(function(event) {
|
||||
event.preventDefault();
|
||||
var deleteSubmit = $("#deleteSubmit").val();
|
||||
$("#conformationMessage").load("app/image/delete_image.php", {
|
||||
$("#sniffle").load("app/image/delete_image.php", {
|
||||
id: <?php echo $_GET['id']; ?>,
|
||||
submit: deleteSubmit
|
||||
});
|
||||
|
@ -260,7 +258,7 @@
|
|||
event.preventDefault();
|
||||
var descriptionInput = $("#descriptionInput").val();
|
||||
var descriptionSubmit = $("#descriptionSubmit").val();
|
||||
$("#conformationMessage").load("app/image/edit_description.php", {
|
||||
$("#sniffle").load("app/image/edit_description.php", {
|
||||
id: <?php echo $_GET['id']; ?>,
|
||||
input: descriptionInput,
|
||||
submit: descriptionSubmit
|
||||
|
@ -294,7 +292,7 @@
|
|||
event.preventDefault();
|
||||
var tagsInput = $("#tagsInput").val();
|
||||
var tagsSubmit = $("#tagsSubmit").val();
|
||||
$("#conformationMessage").load("app/image/edit_tags.php", {
|
||||
$("#sniffle").load("app/image/edit_tags.php", {
|
||||
id: <?php echo $_GET['id']; ?>,
|
||||
input: tagsInput,
|
||||
submit: tagsSubmit
|
||||
|
@ -328,7 +326,7 @@
|
|||
event.preventDefault();
|
||||
var authorInput = $("#authorInput").val();
|
||||
var authorSubmit = $("#authorSubmit").val();
|
||||
$("#conformationMessage").load("app/image/edit_author.php", {
|
||||
$("#sniffle").load("app/image/edit_author.php", {
|
||||
id: <?php echo $_GET['id']; ?>,
|
||||
input: authorInput,
|
||||
submit: authorSubmit
|
||||
|
|
88
upload.php
88
upload.php
|
@ -27,6 +27,27 @@
|
|||
<!-- Flyout script! -->
|
||||
<script src="Flyout/flyout.js"></script>
|
||||
<link rel='stylesheet' href='Flyout/flyout.css'>
|
||||
|
||||
<!-- Upload Script -->
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#uploadSubmit").submit(function(event) {
|
||||
event.preventDefault();
|
||||
var formData = new FormData(this.form);
|
||||
|
||||
$.ajax({
|
||||
url: "app/image/upload_image.php",
|
||||
type: 'post',
|
||||
data: formData,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function(response){
|
||||
$("#sniffle").html(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
|
@ -37,74 +58,15 @@
|
|||
if (!loggedin()) {
|
||||
header("Location: index.php");
|
||||
}
|
||||
|
||||
// Setting up varibles
|
||||
$dir = "images/";
|
||||
$thumb_dir = $dir."thumbnails/";
|
||||
$image_basename = basename($_FILES["image"]["name"]);
|
||||
$image_path = $dir.$image_basename;
|
||||
$file_type = pathinfo($image_path,PATHINFO_EXTENSION);
|
||||
|
||||
// Continue if no errors
|
||||
if (isset($_POST['upload']) && !empty($_FILES["image"]["name"])) {
|
||||
if (empty($error)) {
|
||||
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
|
||||
if (in_array($file_type, $allowed_types)) {
|
||||
// Upload to server
|
||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
||||
// Make thumbnail
|
||||
$image_thumbnail = new Imagick($image_path);
|
||||
$image_thumbnail->resizeImage(300,null,null,1,null);
|
||||
$image_thumbnail->writeImage($thumb_dir.$image_basename);
|
||||
|
||||
// Prepare sql for destruction and filtering the sus
|
||||
$sql = "INSERT INTO swag_table (imagename, alt, author) VALUES (?, ?, ?)";
|
||||
|
||||
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);
|
||||
|
||||
// Setting up parameters
|
||||
$param_image_name = $_FILES["image"]["name"];
|
||||
$param_alt_text = $_POST['alt'];
|
||||
$param_user_id = $_SESSION["id"];
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
$success = "Your Image uploaded successfully!";
|
||||
} else {
|
||||
$error = "Something went fuckywucky, please try later";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = "F, Upload failed";
|
||||
}
|
||||
} else {
|
||||
$error = "File uploaded not supported, file types that are allowed include: JPG, JPEG, PNG and WEBP";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="alert-banner">
|
||||
<?php
|
||||
if (isset($error)) {
|
||||
echo "<script>sniffleAdd('Error', '".$error."', 'var(--red)', '".$root_dir."assets/icons/cross.svg');</script>";
|
||||
}
|
||||
if (isset($success)) {
|
||||
echo "<script>sniffleAdd('Success!', '".$success."', 'var(--green)', '".$root_dir."assets/icons/check.svg');</script>";
|
||||
}
|
||||
?>
|
||||
<script src='scripts/alert.js'></script>
|
||||
</div>
|
||||
|
||||
<div class="upload-root default-window">
|
||||
<h2 class="space-bottom">Upload image</h2>
|
||||
<p>In this world you have 2 choices, to upload a really cute picture of an animal or fursuit, or something other than those 2 things.</p>
|
||||
<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-large" type="text" name="alt" placeholder="Description/Alt for image">
|
||||
<button class="btn alert-high" type="submit" name="upload"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
|
||||
<form id="uploadSubmit" class="flex-down between" method="POST" enctype="multipart/form-data">
|
||||
<input name="image" class="btn alert-default space-bottom" type="file" placeholder="select image UwU">
|
||||
<input name="alt" class="btn alert-default space-bottom-large" type="text" placeholder="Description/Alt for image">
|
||||
<button name="submit" class="btn alert-high" type="submit"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue