" . basename($backup) . " (kept as backup)\n"; if (@mkdir($dataDir, 0777, true)) { echo " created fresh data/ (owned by PHP user)\n"; foreach ($preserved as $f => $c) @file_put_contents($dataDir . '/' . $f, $c); if (testWrite($dataDir)) { echo " data now: " . describe($dataDir) . "\n"; echo "\nSUCCESS via recreate. Old data kept in " . basename($backup) . ".\n"; echo "Re-run onboarding, then DELETE fix_perms.php (and the backup folder if you like).\n"; exit; } echo " still not writable; restoring original...\n"; // best-effort restore @array_map('unlink', glob($dataDir . '/*')); @rmdir($dataDir); } @rename($backup, $dataDir); echo " restored original data/\n"; } else { echo " rename failed (parent not writable enough by PHP)\n"; } } else { echo " parent dir is not writable by PHP — cannot recreate automatically.\n"; } // ── Could not fix from PHP ───────────────────────────────────────────────── echo "\n=========================================================\n"; echo "Could not fix automatically (PHP does not own the folder).\n"; echo "Use your hosting control panel's File Manager (or an FTP client):\n"; echo " 1. Go to the 'pp-integration' folder.\n"; echo " 2. Right-click the 'data' folder -> Change Permissions / CHMOD.\n"; echo " 3. Set it to 777 (read/write/execute for all).\n"; echo " 4. Also set the two .json files inside to 666.\n"; echo "Then reload onboard.php?debug=1 to confirm 'is_writable: yes'.\n"; echo "=========================================================\n";