diff --git a/index.php b/index.php index 52feab3..1d06380 100644 --- a/index.php +++ b/index.php @@ -76,11 +76,15 @@ function loadJsonFile(string $file, array $default): array function saveJsonFile(string $file, array $data): void { - file_put_contents( - $file, - json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), - LOCK_EX - ); + $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + if ($json === false) { + throw new RuntimeException('Konfiguration konnte nicht kodiert werden.'); + } + + $written = @file_put_contents($file, $json, LOCK_EX); + if ($written === false) { + throw new RuntimeException('Konfiguration konnte nicht gespeichert werden. Bitte Dateirechte prüfen.'); + } } function isAdminLoggedIn(): bool