Cannot create $DATA_FILE — folder not writable!"); } } $list = []; $raw = @file_get_contents($DATA_FILE); if ($raw === false) { echo "
";
echo "Raw file content:\n" . htmlspecialchars($raw) . "\n\n";
echo "Parsed items count: " . count($list) . "\n";
if ($list) {
echo "First item: " . htmlspecialchars($list[0]['text'] ?? '???') . "\n";
}
echo "";
// ================= HANDLE ACTIONS =================
$action = $_POST['action'] ?? '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action) {
echo "POST received! Action = $action"; $list = json_decode(file_get_contents($DATA_FILE), true) ?: []; if ($action === 'add' && !empty($_POST['item'])) { $list[] = [ 'text' => trim($_POST['item']), 'checked' => false, 'added' => time() ]; echo "
Added item → count now " . count($list) . ""; } // ... (keep the toggle & delete blocks the same as before) $saved = file_put_contents($DATA_FILE, json_encode($list, JSON_PRETTY_PRINT)); if ($saved === false) { echo "
Saved " . $saved . " bytes OK"; } header("Location: " . $_SERVER['PHP_SELF'] . "?t=" . time()); exit; } ?>