-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload.php
52 lines (35 loc) · 1.05 KB
/
load.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
if (!isset($_GET["x"]) || !isset($_GET["y"]) || !isset($_GET["z"]) || !isset($_GET["provider"])) {
header("HTTP/1.1 404 Not Found");
die("Missing parameters!");
}
$x = intval($_GET["x"]);
$y = intval($_GET["y"]);
$z = intval($_GET["z"]);
$provider = $_GET["provider"];
$provider_config = __DIR__ . "/provider/" . $provider . ".php";
if (!file_exists($provider_config)) {
header("HTTP/1.1 404 Not Found");
die("Provider not found: " . $provider);
}
require($provider_config);
$url = $urls[array_rand($urls)];
$cache_dir = realpath(__DIR__ . "/cache");
if (!is_dir($cache_dir))
mkdir($cache_dir, 0775);
$path = $cache_dir . "/" . $provider . "/" . $z . "/" . $x. "/";
if (!is_dir($path)) {
if (!mkdir($path, 0755, true)) {
header("HTTP/1.1 500 Internal Server Error");
die("Could not create path: " . $path);
}
}
$file = $path . $y . ".png";
if (!copy($url, $file)) {
header("HTTP/1.1 404 Not Found");
die("Could not copy remote file: " . $url);
}
header("HTTP/1.1 200 Found");
header("Content-type: image/png");
echo file_get_contents($file);
?>