From d4e83dcb4aa59d9096e0b3132e413ad41cbfe7b6 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Wed, 7 Sep 2022 14:29:53 +0000 Subject: [PATCH] Rename files on upload --- app/image/upload_image.php | 24 ++++++++++++------------ upload.php | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/image/upload_image.php b/app/image/upload_image.php index c0a2551..135826e 100644 --- a/app/image/upload_image.php +++ b/app/image/upload_image.php @@ -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) { ?> assets/icons/file-search.svg'); + sniffleAdd('Gwha!', 'Pls provide image', 'var(--red)', 'assets/icons/file-search.svg'); } }); }); @@ -58,7 +58,7 @@ if (!loggedin()) { echo " "; }