php-gallery/upload.php

110 lines
3.7 KiB
PHP
Raw Normal View History

2022-08-03 16:46:50 +00:00
<?php include "ui/required.php"; ?>
2022-07-21 14:53:04 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2022-08-03 16:46:50 +00:00
<title>Lynx Gallery</title>
<!-- Google Fonts -->
2022-07-21 14:53:04 +00:00
<link rel="stylesheet" href="css/master.css">
2022-07-23 14:03:11 +00:00
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@600&amp;display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&amp;display=swap">
2022-08-03 16:46:50 +00:00
<!-- JQuery -->
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous">
</script>
2022-07-21 14:53:04 +00:00
</head>
<body>
<?php
2022-08-03 16:46:50 +00:00
include "ui/nav.php";
2022-07-21 14:53:04 +00:00
2022-07-26 20:51:59 +00:00
// Check if user is logged in
2022-08-01 09:31:23 +00:00
if (loggedin()) {
2022-07-26 20:51:59 +00:00
// User is logged in
} else {
$error = "You must be logged in to upload images";
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);
2022-07-21 14:53:04 +00:00
2022-07-26 11:33:28 +00:00
// Prepare sql for destruction and filtering the sus
$sql = "INSERT INTO swag_table (imagename, alt, author) VALUES (?, ?, ?)";
2022-07-21 14:53:04 +00:00
2022-07-26 11:33:28 +00:00
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);
2022-07-21 14:53:04 +00:00
2022-07-26 11:33:28 +00:00
// Setting up parameters
2022-07-26 20:51:59 +00:00
$param_image_name = $_FILES["image"]["name"];
2022-07-26 11:33:28 +00:00
$param_alt_text = $_POST['alt'];
$param_user_id = $_SESSION["id"];
2022-07-26 11:33:28 +00:00
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
2022-07-26 20:51:59 +00:00
$success = "Your Image uploaded successfully!";
2022-07-26 11:33:28 +00:00
} else {
$error = "Something went fuckywucky, please try later";
}
}
2022-07-26 20:51:59 +00:00
} else {
$error = "F, Upload failed";
2022-07-25 17:28:55 +00:00
}
2022-07-23 07:44:43 +00:00
} else {
2022-07-26 20:51:59 +00:00
$error = "File uploaded not supported, file types that are allowed include: JPG, JPEG, PNG and WEBP";
2022-07-21 14:53:04 +00:00
}
}
}
?>
2022-08-01 13:09:53 +00:00
<div class="alert-banner">
<?php
if (isset($error)) {
echo notify($error, "low");
}
if (isset($success)) {
2022-08-01 14:06:27 +00:00
echo notify($success, "high");
2022-08-01 13:09:53 +00:00
}
?>
<script src='scripts/alert.js'></script>
</div>
2022-07-26 17:16:17 +00:00
<div class="upload-root default-window">
2022-07-25 15:13:26 +00:00
<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">
2022-07-26 17:16:17 +00:00
<button class="btn alert-high" type="submit" name="upload"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
2022-07-25 15:13:26 +00:00
</form>
</div>
2022-07-26 12:34:48 +00:00
<?php
2022-08-03 16:46:50 +00:00
include "ui/top.html";
include "ui/footer.php";
2022-07-26 12:34:48 +00:00
?>
2022-07-21 14:53:04 +00:00
</body>
</html>