Initial commit with PHP script

This commit is contained in:
MarStr 2024-08-19 15:15:38 +02:00
commit 89d43be66d

43
index.php Normal file
View File

@ -0,0 +1,43 @@
<?php
// Our API endpoint to either acquire non-existing, or update existing OSM data files.
// At the end, provide the XML data to the Orthographic Python client.
// The folder where we keep all OSM XMLs
$root_folder = "/server/osm/";
if (isset($_POST))
{
// Convert the JSON in POST to an array
$json = json_decode(file_get_contents('php://input'), true);
$filename = $root_folder . $json["tile_lat"] . "-" . $json["square_lat"] . "_" . $json["tile_lng"] . "-" . $json["square_lng"] . ".xml";
$url = "http://www.overpass-api.de/api/xapi?*[bbox=".$json["bbox"]["lng"].",".$json["bbox"]["lat"].",".$json["bbox"]["lng_b"].",".$json["bbox"]["lat_b"]."]";
// Check if the file we are looking for already exists
$t_exists = file_exists($filename);
// If the file exists, check for its age. If it is older than 30 days, update the file.
if ($t_exists == true)
{
$t = filemtime($filename);
if(strtotime($t) < (time()-2592000))
{
$ovp = file_get_contents($url);
file_put_contents($filename, $ovp);
}
}
// If, however, the file does not exist, acquire it from Overpass API
if ($t_exists == false)
{
$ovp = file_get_contents($url);
file_put_contents($filename, $ovp);
}
// Offer the content as stream for Orthographic to download
$xml = file_get_contents($filename);
echo $xml;
}
?>