Initial commit: Modernes Harry Potter Escape Quiz Portal (FastAPI & MariaDB)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Datei, in die gespeichert wird
|
||||
$file = "fragen_vorschlaege.json";
|
||||
|
||||
// Eingehende Daten lesen
|
||||
$input = file_get_contents("php://input");
|
||||
$data = json_decode($input, true);
|
||||
|
||||
if (!$data || !isset($data["frage"]) || !isset($data["antwort"])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["error" => "Ungültige Daten"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Existierende Vorschläge laden
|
||||
$existing = [];
|
||||
if (file_exists($file)) {
|
||||
$json = file_get_contents($file);
|
||||
$existing = json_decode($json, true);
|
||||
if (!is_array($existing)) {
|
||||
$existing = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Neuen Vorschlag anhängen
|
||||
$existing[] = $data;
|
||||
|
||||
// Datei speichern
|
||||
if (file_put_contents($file, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||
echo json_encode(["success" => true]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "Konnte Datei nicht schreiben"]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user