<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$file = __DIR__ . '/situri.geojson';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = file_get_contents('php://input');
    $result = file_put_contents($file, $data);
    if ($result === false) {
        http_response_code(500);
        echo "error writing file";
    } else {
        echo "success";
    }
} else {
    if (file_exists($file) && filesize($file) > 0) {
        header('Content-Type: application/json');
        readfile($file);
    } else {
        header('Content-Type: application/json');
        echo '{"type":"FeatureCollection","features":[]}';
    }
}
?>
