-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache.php
More file actions
29 lines (22 loc) · 714 Bytes
/
cache.php
File metadata and controls
29 lines (22 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$post_data = file_get_contents('php://input');
$id = md5($post_data);
Header("Content-Type: application/json; charset=UTF-8");
if(file_exists("data/{$id}.json")) {
readfile("data/{$id}.json");
}
else {
$ch = curl_init('https://www.overpass-api.de/api/interpreter');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if($response === false) {
Header("HTTP/1.1 500 Internal Server Error");
print "Error receiving response from Overpass API: " . curl_error($ch);
exit(0);
}
file_put_contents("data/{$id}.json", $response);
print $response;
curl_close($ch);
}