This commit is contained in:
Lee 2023-04-15 14:25:54 +01:00
parent e95b57b552
commit 75900d5c12
2 changed files with 8 additions and 22 deletions

@ -10,7 +10,8 @@
</head>
<body>
<!-- Centered div, vertial and horizontal -->
<!-- uploads file to upload.php, shows map id after upload -->
<!-- uploads file to upload.php, shows map id after upload, dont go to upload.php -->
<!-- use js -->
<!-- Modern design, dark mode -->
<div class="flex items-center justify-center h-screen bg-gray-900">
<div class="w-1/2">

@ -16,22 +16,13 @@ function generateMapId()
return $mapId;
}
/**
* Return a JSON response
*/
function returnJson($data): void
{
echo (json_encode($data));
die();
}
/**
* Checks if the file is a zip file
*/
function isZipFile($file)
{
$fileType = strtolower(pathinfo($file, PATHINFO_EXTENSION));
echo $fileType;
return $fileType == "zip";
}
@ -42,18 +33,12 @@ $file = $map["tmp_name"];
if (!isZipFile($file)) {
echo "The file is not a zip file";
return;
die();
}
$target_file = $target_dir . $mapId . ".zip";
if (move_uploaded_file($file, $target_file)) {
returnJson([
"status" => "success",
"mapId" => $mapId
]);
} else {
returnJson([
"status" => "error",
"message" => "An error occurred while uploading the file"
]);
if (!move_uploaded_file($file, $target_file)) {
echo "There was an error uploading the file";
die();
}
echo "The file https://wip.fascinated.cc/maps/" . $mapId . ".zip has been uploaded.";