mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-01-29 17:28:27 +00:00
Rename files on upload
This commit is contained in:
parent
5a6dc1a4b8
commit
d4e83dcb4a
|
@ -16,10 +16,10 @@ if (isset($_POST['submit'])) {
|
|||
$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);
|
||||
// File name updating
|
||||
$file_type = pathinfo($dir.$_FILES['image']['name'],PATHINFO_EXTENSION);
|
||||
$image_newname = "IMG_".$_SESSION["username"]."_".round(microtime(true)).".".$file_type;
|
||||
$image_path = $dir.$image_newname;
|
||||
|
||||
// Allowed file types
|
||||
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
|
||||
|
@ -30,11 +30,11 @@ if (isset($_POST['submit'])) {
|
|||
try {
|
||||
$image_thumbnail = new Imagick($image_path);
|
||||
$image_thumbnail->resizeImage(300,null,null,1,null);
|
||||
$image_thumbnail->writeImage($thumb_dir.$image_basename);
|
||||
$image_thumbnail->writeImage($thumb_dir.$image_newname);
|
||||
} catch (Exception $e) {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Gwha!', 'We hit a small roadbump during making of the thumbail. We will continue anyway!', 'var(--black)', '".$root_dir."assets/icons/bug.svg');
|
||||
sniffleAdd('Gwha!', 'We hit a small roadbump during making of the thumbail. We will continue anyway!', 'var(--black)', 'assets/icons/bug.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ if (isset($_POST['submit'])) {
|
|||
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_image_name = $image_newname;
|
||||
$param_alt_text = $_POST['alt'];
|
||||
$param_user_id = $_SESSION['id'];
|
||||
|
||||
|
@ -55,13 +55,13 @@ if (isset($_POST['submit'])) {
|
|||
if (mysqli_stmt_execute($stmt)) {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd(':3', 'Your Image uploaded successfully!', 'var(--green)', '".$root_dir."assets/icons/check.svg');
|
||||
sniffleAdd(':3', 'Your Image uploaded successfully!', 'var(--green)', 'assets/icons/check.svg');
|
||||
</script>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd(':c', 'Something went fuckywucky, please try later', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||
sniffleAdd(':c', 'Something went fuckywucky, please try later', 'var(--red)', 'assets/icons/cross.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
@ -69,21 +69,21 @@ if (isset($_POST['submit'])) {
|
|||
} 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)', '".$root_dir."assets/icons/bug.svg');
|
||||
sniffleAdd('Hmmff', 'Something happened when moving the file to the server. This may just been a 1-off so try again', 'var(--red)', '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)', '".$root_dir."assets/icons/cross.svg');
|
||||
sniffleAdd('Woopsie', 'The file type you are trying to upload is not supported. Supported files include: JPEG, JPG, PNG and WEBP', 'var(--red)', 'assets/icons/cross.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Denied!!!', 'As you are not loggedin, your upload has been stopped, L', 'var(--red)', '".$root_dir."assets/icons/cross.svg');
|
||||
sniffleAdd('Denied!!!', 'As you are not loggedin, your upload has been stopped, L', 'var(--red)', 'assets/icons/cross.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
$("#alt").val("");
|
||||
$("#submit").val("");
|
||||
} else {
|
||||
sniffleAdd('Gwha!', 'Pls provide image', 'var(--red)', '<?php echo $root_dir; ?>assets/icons/file-search.svg');
|
||||
sniffleAdd('Gwha!', 'Pls provide image', 'var(--red)', 'assets/icons/file-search.svg');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -58,7 +58,7 @@
|
|||
if (!loggedin()) {
|
||||
echo "
|
||||
<script>
|
||||
sniffleAdd('Who are you!', 'You must be loggedin to upload things, sowwy!', 'var(--red)', '" . $root_dir . "assets/icons/cross.svg');
|
||||
sniffleAdd('Who are you!', 'You must be loggedin to upload things, sowwy!', 'var(--red)', 'assets/icons/cross.svg');
|
||||
</script>
|
||||
";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue