From 4b65c7f0232b9543696761833ec0b856936f1a31 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sun, 9 Apr 2023 12:05:53 +0100 Subject: [PATCH] add check to see if file already exists --- upload.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/upload.php b/upload.php index 7ac0360..0743b90 100644 --- a/upload.php +++ b/upload.php @@ -47,6 +47,13 @@ if (!isset($file)) { $target_file = $_FILES["sharex"]["name"]; // File name $fileType = pathinfo($target_file, PATHINFO_EXTENSION); // File extension (e.g. png, jpg, etc.) +// Check if the file already exists +if (file_exists($uploadDir . $target_file)) { + $timeTaken = microtime(true) - $before; + returnJson('ERROR', 'File already exists', $timeTaken); + die(); +} + if (in_array($fileType, array("png", "jpeg", "jpg"))) { // Convert to webp $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"]));