source: src/webapp/webservice/mapupload.php@ 9e7eb31

debian/bullseye debian/jessie
Last change on this file since 9e7eb31 was f03591a, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago
  • Improved webclient file uploading
  • Improvded webservice
    • Map uploading
    • tileserver searches it's maps under maps now
  • Maps have spoken names now (set by the user during upload)
  • Moved to leaflet 1.1.0
  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[d7e6e9c]1<?php
2/*
[f03591a]3 Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
[d7e6e9c]4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
[6f38643]18
[f03591a]19function setMapName($mbTilesFile, $mapName)
20{
21 if(!is_file($mbTilesFile))
22 return array(false, "setMapName - Map file not found: ". $mbTilesFile);
23 if(empty($mapName) || $mapName == "")
24 return array(false, "setMapName - Map name empty");
25 try{
26 $databaseConnection = new PDO("sqlite:". $mbTilesFile);
27 $databaseConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
28
29 $query = $databaseConnection->prepare("UPDATE metadata SET value=:value WHERE name='name'");
30 $query->bindParam(":value", $mapName);
31 $query->execute();
32 return array(true, "");
33 }
34 catch(PDOException $e){
35 return array(false, "setMapName - Database error: ". $e->getMessage());
36 }
37}
38
39header('Content-type: application/json');
40
41$result["error"] = 1;
42$result["errormessage"] = "Unknown Error";
43
44if(!array_key_exists("mapName", $_POST)){
45 $result["error"] = 1;
46 $result["errormessage"] = "Please specify map name (no value)";
47 echo json_encode($result);
48 return;
49}
50$mapName = $_POST["mapName"];
51if(empty($mapName) || $mapName == ""){
52 $result["error"] = 1;
53 $result["errormessage"] = "Please specifiy map name (empty value)";
54 echo json_encode($result);
55 return;
56}
[6f38643]57
[f03591a]58$mapDirectory = __DIR__ ."/maps";
[4972eea]59if(!array_key_exists("mapFile", $_FILES)){
[f03591a]60 $result["error"] = 1;
61 $result["errormessage"] = "No map file recieved";
[6f38643]62 echo json_encode($result);
63 return;
64}
[f03591a]65if (!isset($_FILES['mapFile']['error']) || is_array($_FILES['mapFile']['error'])){
66 $result["error"] = 1;
67 $result["errormessage"] = "Invalid parameters";
68 echo json_encode($result);
69 return;
70}
71switch ($_FILES['mapFile']['error']) {
72 case UPLOAD_ERR_OK:
73 break;
74 case UPLOAD_ERR_NO_FILE:
75 $result["error"] = 1;
76 $result["errormessage"] = "No file sent";
77 echo json_encode($result);
78 return;
79 case UPLOAD_ERR_INI_SIZE:
80 case UPLOAD_ERR_FORM_SIZE:
81 $result["error"] = 1;
82 $result["errormessage"] = "Exceeded filesize limit.";
83 echo json_encode($result);
84 return;
85 default:
86 $result["error"] = 1;
87 $result["errormessage"] = "Unknown PHP Error";
88 echo json_encode($result);
89 return;
90}
91$mapFileName = $mapDirectory ."/". sha1_file($_FILES['mapFile']['tmp_name']) .".mbtiles";
92if(move_uploaded_file($_FILES['mapFile']['tmp_name'], $mapFileName)){
93 // correct map metadata
94 $resultRename = setMapName($mapFileName, $mapName);
95 if($resultRename[0] === true){
96 $result["error"] = 0;
97 $result["errormessage"] = "";
[6f38643]98 }
[f03591a]99 else{
100 $result["error"] = 1;
101 $result["errormessage"] = $resultRename[1];
102 }
103}
104else {
105 $result["error"] = 1;
106 $result["errormessage"] = "Could not move map in place";
[6f38643]107}
108echo json_encode($result);
109
[d7e6e9c]110?>
Note: See TracBrowser for help on using the repository browser.