add check to see if file already exists

This commit is contained in:
Lee 2023-04-09 12:05:53 +01:00
parent c62cf31b99
commit 4b65c7f023

@ -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"]));