<?php
/**
 * Background unzip via nohup
 */
header('Content-Type: text/plain');

$zip = __DIR__ . '/bio_uploads.zip';
$dest = __DIR__;
$log = __DIR__ . '/unzip_log.txt';

if (!file_exists($zip)) {
    die("ZIP not found\n");
}

// Check if already extracted
if (is_dir(__DIR__ . '/wp-content/uploads/2026/04/homepage')) {
    $files = glob(__DIR__ . '/wp-content/uploads/2026/04/homepage/*');
    if (count($files) > 5) {
        echo "Already extracted! " . count($files) . " homepage files found.\n";
        exit;
    }
}

// Start background unzip
$cmd = "cd " . escapeshellarg($dest) . " && nohup unzip -o " . escapeshellarg($zip) . " > " . escapeshellarg($log) . " 2>&1 &";
exec($cmd);
echo "Unzip started in background.\n";
echo "Check progress: https://www.bio.razdijital.com/bio_unzip_status.php\n";
