<?php
// Production Setup Script
header('Content-Type: text/plain');

$folders = ['data', 'uploads'];

echo "--- Ghadget Production Setup ---\n";

foreach ($folders as $f) {
    if (!is_dir($f)) {
        echo "Creating '$f' directory... ";
        if (mkdir($f, 0777, true)) {
            echo "OK\n";
        } else {
            echo "FAILED (Check parent permissions)\n";
        }
    } else {
        echo "'$f' exists.\n";
    }

    echo "Setting permissions for '$f' to 777... ";
    if (@chmod($f, 0777)) {
        echo "OK\n";
    } else {
        echo "FAILED (May need manual chmod via cPanel/FTP)\n";
    }

    // Create dummy files to ensure writability
    $testFile = $f . '/test_write.txt';
    if (@file_put_contents($testFile, 'test')) {
        echo "Write Check: OK\n";
        unlink($testFile);
    } else {
        echo "Write Check: FAILED. PHP cannot write to this folder.\n";
    }
    echo "\n";
}

echo "Setup Complete. Delete this file if desired.\n";
