<?php
$placeId = $_GET['place_id'];
$placeDetails = getPlaceDetails($placeId);
$jsonResponse = json_encode($placeDetails);

$resFile = "detailjson/detail_".time().".txt";
file_put_contents($resFile, $jsonResponse);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($resFile) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($resFile));
readfile($resFile);
exit;



function getPlaceDetails($placeId) {
    $apiKey = "AIzaSyAq1ODKKCVgTT3yvuqrsSIL8biDjhNu8NM";
    $url = 'https://maps.googleapis.com/maps/api/place/details/json';
    $url .= '?place_id=' . urlencode($placeId) . '&key=' . urlencode($apiKey);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        return ['error' => 'Request failed: ' . curl_error($ch)];
    }
    curl_close($ch);

    $data = json_decode($response, true);

    if (isset($data['status']) && $data['status'] === 'OK') {
        return $data['result'];
    } else {
        return ['error' => 'Error: ' . $data['status']];
    }
}



