mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-05-22 19:34:54 +00:00
It finally works
This commit is contained in:
parent
7c13b6478d
commit
c18d72ccb0
2 changed files with 84 additions and 60 deletions
|
@ -11,72 +11,80 @@ session_start();
|
||||||
include "../server/conn.php";
|
include "../server/conn.php";
|
||||||
|
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
// Root paths
|
if (isset($_SESSION['id'])) {
|
||||||
$dir = "images/";
|
// Root paths
|
||||||
$thumb_dir = $dir."thumbnails/";
|
$dir = "../../images/";
|
||||||
|
$thumb_dir = $dir."thumbnails/";
|
||||||
|
|
||||||
// File paths
|
// File paths
|
||||||
$image_basename = basename($_FILES['image']['name']);
|
$image_basename = basename($_FILES['image']['name']);
|
||||||
$image_path = $dir.$image_basename;
|
$image_path = $dir.$image_basename;
|
||||||
$file_type = pathinfo($image_path,PATHINFO_EXTENSION);
|
$file_type = pathinfo($image_path,PATHINFO_EXTENSION);
|
||||||
|
|
||||||
// Allowed file types
|
// Allowed file types
|
||||||
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
|
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
|
||||||
if (in_array($file_type, $allowed_types)) {
|
if (in_array($file_type, $allowed_types)) {
|
||||||
// Move file to server
|
// Move file to server
|
||||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {
|
||||||
// Attempt making a thumbnail
|
// Attempt making a thumbnail
|
||||||
try {
|
try {
|
||||||
$image_thumbnail = new Imagick($image_path);
|
$image_thumbnail = new Imagick($image_path);
|
||||||
$image_thumbnail->resizeImage(300,null,null,1,null);
|
$image_thumbnail->resizeImage(300,null,null,1,null);
|
||||||
$image_thumbnail->writeImage($thumb_dir.$image_basename);
|
$image_thumbnail->writeImage($thumb_dir.$image_basename);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
?>
|
echo "
|
||||||
<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>
|
<script>
|
||||||
sniffleAdd(':3', 'Your Image uploaded successfully!', 'var(--green)', '<?php echo $root_dir; ?>assets/icons/check.svg');
|
sniffleAdd('Gwha!', 'We hit a small roadbump during making of the thumbail. We will continue anyway!', 'var(--black)', '".$root_dir."assets/icons/bug.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
";
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<script>
|
|
||||||
sniffleAdd(':c', 'Something went fuckywucky, please try later', 'var(--red)', '<?php echo $root_dir; ?>assets/icons/cross.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)) {
|
||||||
|
echo "
|
||||||
|
<script>
|
||||||
|
sniffleAdd(':3', 'Your Image uploaded successfully!', 'var(--green)', '".$root_dir."assets/icons/check.svg');
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
} else {
|
||||||
|
echo "
|
||||||
|
<script>
|
||||||
|
sniffleAdd(':c', 'Something went fuckywucky, please try later', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "
|
||||||
|
<script>
|
||||||
|
sniffleAdd('Hmmff', 'Something happened when moving the file to the server. This may just been a 1-off so try again', 'var(--red)', '".$root_dir."assets/icons/bug.svg');
|
||||||
|
</script>
|
||||||
|
";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
?>
|
echo "
|
||||||
<script>
|
<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');
|
sniffleAdd('Woopsie', 'The file type you are trying to upload is not supported. Supported files include: JPEG, JPG, PNG and WEBP', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
?>
|
echo "
|
||||||
<script>
|
<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');
|
sniffleAdd('Denied!!!', 'As you are not loggedin, your upload has been stopped, L', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
upload.php
28
upload.php
|
@ -33,10 +33,22 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#uploadSubmit").submit(function(event) {
|
$("#uploadSubmit").submit(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var formData = new FormData(this.form);
|
// Make form
|
||||||
|
var formData = new FormData();
|
||||||
|
|
||||||
|
// Get image
|
||||||
|
var image_data = $("#image").prop("files")[0];
|
||||||
|
formData.append("image", image_data);
|
||||||
|
// Get ALT
|
||||||
|
var alt = $("#alt").val();
|
||||||
|
formData.append("alt", alt);
|
||||||
|
// Get ALT
|
||||||
|
var submit = $("#submit").val();
|
||||||
|
formData.append("submit", submit);
|
||||||
|
|
||||||
|
// Upload the information
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "app/image/upload_image.php",
|
url: 'app/image/upload_image.php',
|
||||||
type: 'post',
|
type: 'post',
|
||||||
data: formData,
|
data: formData,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
@ -56,7 +68,11 @@
|
||||||
|
|
||||||
// Check if user is logged in
|
// Check if user is logged in
|
||||||
if (!loggedin()) {
|
if (!loggedin()) {
|
||||||
header("Location: index.php");
|
echo "
|
||||||
|
<script>
|
||||||
|
sniffleAdd('Who are you!', 'You must be loggedin to upload things, sowwy!', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||||
|
</script>
|
||||||
|
";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -64,9 +80,9 @@
|
||||||
<h2 class="space-bottom">Upload image</h2>
|
<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>
|
<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 id="uploadSubmit" class="flex-down between" method="POST" enctype="multipart/form-data">
|
<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 id="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">
|
<input id="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>
|
<button id="submit" class="btn alert-high" type="submit"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue