70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
<?php
|
||
|
||
// error_reporting(E_ALL | E_STRICT);
|
||
// ini_set('display_errors','On');
|
||
|
||
ini_set('display_errors','Off'); //Чтоб ошибки не отправлялись клиентам
|
||
//ini_set("error_log", "php-error.log"); //Закоментил потому что удобней смотреть в 1м месте а не лазить по всем папкам...
|
||
date_default_timezone_set("UTC"); //Чтоб всё было по гринвичу
|
||
|
||
function createPath($path)
|
||
{
|
||
if (is_dir($path)) return true;
|
||
$prev_path = substr($path, 0, strrpos($path, '/', -2) + 1 );
|
||
$return = createPath($prev_path);
|
||
return ($return && is_writable($prev_path)) ? mkdir($path) : false;
|
||
}
|
||
|
||
if(isset($_REQUEST['x'])) $x=$_REQUEST['x']; else $x='';
|
||
if(isset($_REQUEST['y'])) $y=$_REQUEST['y']; else $y='';
|
||
if(isset($_REQUEST['z'])) $z=$_REQUEST['z']; else $z='';
|
||
if(isset($_REQUEST['s'])) $s=$_REQUEST['s']; else $s='';
|
||
if(isset($_REQUEST['lyrs'])) $lyrs=$_REQUEST['lyrs']; else $lyrs='m'; //Тип карты гибрид или чтото другое
|
||
|
||
//Проверяем есть ли файл в буфере
|
||
if (file_exists('./google/'.$lyrs.'/'.$z.'/'.$x.'/'.$y.'.png'))
|
||
{
|
||
//Чтоб переписать старенькие
|
||
$time_sec=time();
|
||
$time_file=filemtime('./google/'.$lyrs.'/'.$z.'/'.$x.'/'.$y.'.png');
|
||
$time=$time_sec-$time_file;
|
||
if($time<3*30*24*60*60) //Не старше 3х месяцев
|
||
{
|
||
header("Content-Type: image/png");
|
||
readfile('./google/'.$lyrs.'/'.$z.'/'.$x.'/'.$y.'.png');
|
||
Exit();
|
||
}
|
||
}
|
||
|
||
//Request URL: http://uspdmanager.istt.kz/get.php?hl=ru-RU&lyrs=m&x=357&y=193&z=9&s=
|
||
|
||
//$key = "YOUR KEY HERE";
|
||
//$url = "http://maps.google.com/maps/geo?q=".$address."&output=csv&key=".$key;
|
||
//$url = 'http://mt2.google.com/vt/v=w2.114&hl=ru-RU&gl=cn&&x='.$x.'&y='.$y.'&z='.$z.'&s='.$s;
|
||
$url = 'http://mt1.google.com/vt/lyrs='.$lyrs.'@199000000&hl=ru&src=app&x='.$x.'&y='.$y.'&z='.$z.'&s=Galileo';
|
||
//$url = 'http://mt1.google.com/vt/lyrs=m@152000000&hl=ru&x='.$x.'&y='.$y.'&z='.$z.'&s=Gali';
|
||
|
||
|
||
//Загружаем с помощью CURL
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_HEADER,0); //Change this to a 1 to return headers
|
||
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
|
||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
$data = curl_exec($ch);
|
||
curl_close($ch);
|
||
|
||
//Сохраняем файл в буфер
|
||
if(strlen($data)>0)
|
||
{
|
||
createPath('./google/'.$lyrs.'/'.$z.'/'.$x);
|
||
$fp = fopen('./google/'.$lyrs.'/'.$z.'/'.$x.'/'.$y.'.png', 'w');
|
||
fwrite($fp, $data);
|
||
fclose($fp);
|
||
}
|
||
|
||
header("Content-Type: image/png");
|
||
echo $data;
|
||
|