diff --git a/index.php b/index.php index f56b59c..b2fb221 100644 --- a/index.php +++ b/index.php @@ -19,6 +19,18 @@ + + @@ -58,19 +70,6 @@ ?> - - \ No newline at end of file diff --git a/upload.php b/upload.php index 582dd2c..df9d4e4 100644 --- a/upload.php +++ b/upload.php @@ -35,6 +35,22 @@ if (!isZipFile($map["name"])) { die(); } +$fileHash = hash_file("sha256", $file); // the hash of the file + +$exists = false; +foreach (scandir($target_dir) as $file) { // scan the maps directory for a file with the same hash + if (hash_file("sha256", $target_dir . $file) == $fileHash) { + $mapId = pathinfo($file, PATHINFO_FILENAME); + $exists = true; + break; + } +} + +if ($exists) { // if the file already exists, redirect to the existing file + header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip"); + die(); +} + $target_file = $target_dir . $mapId . ".zip"; if (!move_uploaded_file($file, $target_file)) { echo "There was an error uploading the file";