<?php

// JSONファイルのパス

$dataFile = 'data.json';

// クライアントからのリクエスト(JSON)を受け取る

$inputData = file_get_contents('php://input');

// JSON形式か確認

if (json_decode($inputData) === null) {

http_response_code(400);

echo json_encode(['message' => 'Invalid JSON format']);

exit;

}

// JSONデータをファイルに保存

if (file_put_contents($dataFile, $inputData) !== false) {

header('Content-Type: application/json');

echo json_encode(['message' => 'Data saved successfully']);

} else {

http_response_code(500);

echo json_encode(['message' => 'Failed to save data']);

}

?>