2023-04-15 13:13:25 +00:00
|
|
|
<?php
|
|
|
|
header('Content-type:application/json;charset=utf-8'); // Set the response content type to JSON
|
|
|
|
|
|
|
|
$target_dir = "./maps/";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a random map id
|
|
|
|
*/
|
|
|
|
function generateMapId()
|
|
|
|
{
|
|
|
|
$mapId = "";
|
|
|
|
$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
2023-04-15 17:11:15 +00:00
|
|
|
for ($i = 0; $i < 4; $i++) {
|
2023-04-15 13:13:25 +00:00
|
|
|
$mapId .= $characters[rand(0, strlen($characters) - 1)];
|
|
|
|
}
|
|
|
|
return $mapId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the file is a zip file
|
|
|
|
*/
|
|
|
|
function isZipFile($file)
|
|
|
|
{
|
|
|
|
$fileType = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
|
|
|
return $fileType == "zip";
|
|
|
|
}
|
|
|
|
|
|
|
|
$mapId = generateMapId(); // the id of the map
|
|
|
|
|
2023-04-15 13:35:21 +00:00
|
|
|
$map = $_FILES["map"]; // the file to upload
|
|
|
|
$file = $map["tmp_name"]; // the temporary file path
|
2023-04-15 13:13:25 +00:00
|
|
|
|
2023-04-15 13:35:21 +00:00
|
|
|
if (!isZipFile($map["name"])) {
|
2023-04-15 13:13:25 +00:00
|
|
|
echo "The file is not a zip file";
|
2023-04-15 13:25:54 +00:00
|
|
|
die();
|
2023-04-15 13:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$target_file = $target_dir . $mapId . ".zip";
|
2023-04-15 13:25:54 +00:00
|
|
|
if (!move_uploaded_file($file, $target_file)) {
|
|
|
|
echo "There was an error uploading the file";
|
|
|
|
die();
|
2023-04-15 13:13:25 +00:00
|
|
|
}
|
2023-04-15 14:02:44 +00:00
|
|
|
|
|
|
|
// redirect to /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip
|
|
|
|
header("Location: /?map=https://wip.fascinated.cc/maps/" . $mapId . ".zip");
|