100000000) { // if the file is larger than 100MB echo "The file is too large"; die(); } if (!isZipFile($map["name"])) { echo "The file is not a zip file"; 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 ($file == "." || $file == "..") { // ignore the . and .. files continue; } 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"; die(); } // redirect to /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip");