open($file) === true) { if ($zip->locateName("info.dat", ZipArchive::FL_NOCASE) === false) { return false; } $zip->close(); return true; } return false; } try { $map = $_FILES["map"]; // the file to upload if (!isset($map)) { // if the file is not set header("Location: /?map=No file was uploaded"); die(); } $mapId = generateMapId(); // the id of the map $file = $map["tmp_name"]; // the temporary file path $size = $map["size"]; // the size of the file if ($size > 100000000) { // if the file is larger than 100MB header("Location: /?map=File is too large"); die(); } if (!isValidBeatSaberMap($file)) { header("Location: /?map=This is not a valid BeatSaber map"); die(); } $fileHash = hash_file("sha256", $file); // the hash of the file $exists = false; foreach (scandir($target_dir) as $scannedFile) { // scan the maps directory for a file with the same hash if ($scannedFile == "." || $scannedFile == "..") { // ignore the . and .. files continue; } if (hash_file("sha256", $target_dir . $scannedFile) == $fileHash) { $mapId = pathinfo($scannedFile, 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"; // the output file path if (!move_uploaded_file($file, $target_file)) { error_log("Error: Failed to move uploaded file from $file to $target_file"); header("Location: /?map=Failed to upload file"); die(); } header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip"); } catch (Exception $e) { echo "There was an error uploading the file. Error: " . $e->getMessage(); die(); }