23 lines
592 B
PHP
23 lines
592 B
PHP
<?php
|
|
|
|
function readJsonFile($filename) {
|
|
$filepath = __DIR__ . '/../data/' . $filename;
|
|
if (!file_exists($filepath)) {
|
|
return [];
|
|
}
|
|
$content = file_get_contents($filepath);
|
|
return json_decode($content, true) ?? [];
|
|
}
|
|
|
|
function writeJsonFile($filename, $data) {
|
|
$filepath = __DIR__ . '/../data/' . $filename;
|
|
$json = json_encode($data, JSON_PRETTY_PRINT);
|
|
return file_put_contents($filepath, $json);
|
|
}
|
|
|
|
function ensureDataDirectory() {
|
|
$dataDir = __DIR__ . '/../data';
|
|
if (!file_exists($dataDir)) {
|
|
mkdir($dataDir, 0755, true);
|
|
}
|
|
}
|