add invalid hash check

This commit is contained in:
Lee 2023-04-15 19:03:11 +01:00
parent e2b96b37c6
commit af520d265d

@ -47,9 +47,14 @@ if (!isZipFile($map["name"])) {
die(); die();
} }
$fileHash = null;
try {
$fileHash = hash_file("sha256", $file); // the hash of the file $fileHash = hash_file("sha256", $file); // the hash of the file
} catch (Exception $e) {
}
$exists = false; $exists = false;
if ($fileHash != null) {
foreach (scandir($target_dir) as $file) { // scan the maps directory for a file with the same hash 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) { if (hash_file("sha256", $target_dir . $file) == $fileHash) {
$mapId = pathinfo($file, PATHINFO_FILENAME); $mapId = pathinfo($file, PATHINFO_FILENAME);
@ -57,6 +62,7 @@ foreach (scandir($target_dir) as $file) { // scan the maps directory for a file
break; break;
} }
} }
}
if ($exists) { // if the file already exists, redirect to the existing file if ($exists) { // if the file already exists, redirect to the existing file
header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip"); header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip");