return same map id if it already has been uploaded
This commit is contained in:
parent
02d093e773
commit
5d35694d93
25
index.php
25
index.php
@ -19,6 +19,18 @@
|
|||||||
<meta name="twitter:description" content="Simple website to host WIP BeatSaber maps" />
|
<meta name="twitter:description" content="Simple website to host WIP BeatSaber maps" />
|
||||||
<meta property="theme-color" content="#4d3a9c" />
|
<meta property="theme-color" content="#4d3a9c" />
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function copy() {
|
||||||
|
navigator.clipboard.writeText("!wip <?php echo $_GET["map"]; ?>");
|
||||||
|
Swal.fire({
|
||||||
|
icon: "success",
|
||||||
|
title: "Copied to clipboard",
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -58,19 +70,6 @@
|
|||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function copy() {
|
|
||||||
navigator.clipboard.writeText("!wip <?php echo $_GET["map"]; ?>");
|
|
||||||
Swal.fire({
|
|
||||||
position: "top-end",
|
|
||||||
icon: "success",
|
|
||||||
title: "Copied to clipboard",
|
|
||||||
showConfirmButton: false,
|
|
||||||
timer: 1000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
16
upload.php
16
upload.php
@ -35,6 +35,22 @@ if (!isZipFile($map["name"])) {
|
|||||||
die();
|
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";
|
$target_file = $target_dir . $mapId . ".zip";
|
||||||
if (!move_uploaded_file($file, $target_file)) {
|
if (!move_uploaded_file($file, $target_file)) {
|
||||||
echo "There was an error uploading the file";
|
echo "There was an error uploading the file";
|
||||||
|
Reference in New Issue
Block a user