PHPGallery/upload.php
Fluffy-Bean a6b9ab0e5a Removed fullscreen close button
Fixed button colours
Added primary/good options for some assets
2022-11-10 11:27:40 +00:00

111 lines
No EOL
3.9 KiB
PHP

<?php
require __DIR__."/app/required.php";
use App\Account;
$user_info = new Account();
// Check if user is logged in
if (!$user_info->is_loggedin($conn)) {
$_SESSION['err'] = "You must be logged in to upload images!!!!!!!!";
header("location: account.php");
}
?>
<!DOCTYPE html>
<html lang="">
<head>
<?php include __DIR__."/assets/ui/header.php"; ?>
</head>
<body>
<?php include __DIR__."/assets/ui/nav.php"; ?>
<div class="upload-root defaultDecoration defaultSpacing defaultFonts">
<h2>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>
<img id="imagePreview" src="">
<span id="imagePreviewBlock"></span>
<br>
<form id="uploadSubmit" class="flex-down between" method="POST" enctype="multipart/form-data">
<input id="image" class="btn btn-neutral" type="file" placeholder="select image UwU">
<br>
<input id="alt" class="btn btn-neutral" placeholder="Description/Alt for image" type='text'>
<input id="tags" class="btn btn-neutral" placeholder="Tags, seperated by spaces" type='text'>
<br>
<button id="submit" class="btn btn-primary" type="submit"><img class="svg" src="assets/icons/upload.svg">Upload Image</button>
</form>
<script>
image.onchange = evt => {
const [file] = image.files
if (file && file.src !== "") {
imagePreview.src = URL.createObjectURL(file);
imagePreview.style.display = "flex";
document.getElementById("imagePreviewBlock").style.display = "none";
} else {
imagePreview.style.display = "none";
document.getElementById("imagePreviewBlock").style.display = "block";
}
}
</script>
</div>
<script>
$('#uploadSubmit').submit(function(event) {
event.preventDefault();
// Check if image available
var file = $("#image").val();
if (file == "") {
sniffleAdd('Gwha!', 'Pls provide image', 'var(--warning)', 'assets/icons/file-search.svg');
} else {
// 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 TAGS
var tags = $("#tags").val();
formData.append("tags", tags);
// Submit data
var submit = $("#submit").val();
formData.append("submit", submit);
// Upload the information
$.ajax({
url: 'app/image/upload_image.php',
type: 'post',
data: formData,
contentType: false,
processData: false,
success: function (response) {
$("#newSniff").html(response);
document.getElementById("imagePreview").style.display = "none";
document.getElementById("imagePreviewBlock").style.display = "block";
},
error: function (response) {
$("#newSniff").html(response);
document.getElementById("imagePreview").style.display = "none";
document.getElementById("imagePreviewBlock").style.display = "block";
}
});
// Empty values
imagePreview.src = "";
$("#image").val("");
$("#alt").val("");
$("#tags").val("");
$("#submit").val("");
}
});
</script>
<?php include __DIR__."/assets/ui/footer.php"; ?>
</body>
</html>