diff --git a/web-gui/file.php b/web-gui/file.php
new file mode 100644
index 0000000..b2ac0e6
--- /dev/null
+++ b/web-gui/file.php
@@ -0,0 +1,34 @@
+
+
+
+
+
+ Please wait while the map is being generated. This may take up to 10 minutes.
.
+
+
diff --git a/web-gui/functions.php b/web-gui/functions.php
new file mode 100644
index 0000000..2f9ede6
--- /dev/null
+++ b/web-gui/functions.php
@@ -0,0 +1,35 @@
+load($file)) {
+ return FALSE;
+ }
+
+ // Search for Kml->Document->Placemark elements.
+ $placemarks = $dom->getElementsByTagName('kml')->item(0)
+ ?->getElementsByTagName('Document')->item(0)
+ ?->getElementsByTagName('Placemark');
+
+ if (!$placemarks->length > 0) {
+ return FALSE;
+ }
+
+ // Search for Placemark->name element with the value of "squadrats".
+ foreach ($placemarks as $placemark) {
+ $name = $placemark->getElementsByTagName('name')->item(0)?->textContent;
+
+ if ($name === 'squadrats') {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
diff --git a/web-gui/index.php b/web-gui/index.php
index 72d795f..37cf643 100644
--- a/web-gui/index.php
+++ b/web-gui/index.php
@@ -53,31 +53,6 @@
- Download and save a kml-file of the visited squadrats and squadratinhos from Squadrats (Map - Download KML)
diff --git a/web-gui/upload.php b/web-gui/upload.php
index 80ed913..8e613ea 100644
--- a/web-gui/upload.php
+++ b/web-gui/upload.php
@@ -1,42 +1,8 @@
-
-
load($file)) {
- return FALSE;
- }
-
- // Search for Kml->Document->Placemark elements.
- $placemarks = $dom->getElementsByTagName('kml')->item(0)
- ?->getElementsByTagName('Document')->item(0)
- ?->getElementsByTagName('Placemark');
-
- if (!$placemarks->length > 0) {
- return FALSE;
- }
-
- // Search for Placemark->name element with the value of "squadrats".
- foreach ($placemarks as $placemark) {
- $name = $placemark->getElementsByTagName('name')->item(0)?->textContent;
-
- if ($name === 'squadrats') {
- return TRUE;
- }
- }
- return FALSE;
-}
+require __DIR__ . '/functions.php';
-$tmpName = $_FILES['fileToUpload']['tmp_name'];
+$tmpName = $_FILES['fileToUpload']['tmp_name'] ?? NULL;
if (empty($tmpName) || !is_valid_squadrats_kml($tmpName)) {
die("Invalid .kml file.");
@@ -85,26 +51,8 @@ function is_valid_squadrats_kml($file): bool {
setcookie("MissingSquadrats", json_encode($cookieValues), time() + (86400 * 30)); // 86400 = 1 day
}
-?>
-
-
-
-
-
-
-
-
Upload a kml file
-
-Everything ok. Please go back to the main page
-
-\r\n";
-if (move_uploaded_file($tmpName, $target_dir . $fileName . '.kml')) {
- echo "The file ". $fileName . " has been uploaded.
\r\n";
-} else {
- echo "Sorry, there was an error uploading your file.
\r\n";
- exit;
+if (!move_uploaded_file($tmpName, $target_dir . $fileName . '.kml')) {
+ die("Sorry, there was an error uploading your file.");
}
$job = implode(',', [
@@ -118,8 +66,10 @@ function is_valid_squadrats_kml($file): bool {
'lineColor' => $lineColor,
'zoomLevel' => $zoomLevel,
]);
-file_put_contents($target_dir . $fileName . '.csv', $job);
-?>
-
-
+if (!file_put_contents($target_dir . $fileName . '.csv', $job)) {
+ die("Sorry, there was an error uploading your file.");
+}
+
+header('Location: file.php?file=' . $fileName);
+exit;