����JFIF��`�`�����Viewing File: /home/u820193700/domains/throtllr.in/public_html/api/upload_360.php
<?php
// api/upload_360.php
require_once '../includes/db.php';
require_once '../includes/functions.php';

// Check admin auth (mocked for now)
// if (!is_logged_in()) { die("Unauthorized"); }

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['zip_file'])) {
    $bike_id = intval($_POST['bike_id'] ?? 0);
    if ($bike_id === 0) {
        die("Invalid Bike ID");
    }

    $zipFile = $_FILES['zip_file']['tmp_name'];
    $zipFileName = $_FILES['zip_file']['name'];
    
    // Validate it's a zip
    $ext = pathinfo($zipFileName, PATHINFO_EXTENSION);
    if (strtolower($ext) !== 'zip') {
        die("Only ZIP files are allowed.");
    }

    $extractPath = '../assets/uploads/360/bike_' . $bike_id . '/';
    
    if (!file_exists($extractPath)) {
        mkdir($extractPath, 0777, true);
    } else {
        // Clear existing files
        array_map('unlink', glob("$extractPath/*.*"));
    }

    $zip = new ZipArchive;
    if ($zip->open($zipFile) === TRUE) {
        $zip->extractTo($extractPath);
        $zip->close();
        
        // Count frames (jpg/png)
        $files = glob($extractPath . "*.{jpg,jpeg,png}", GLOB_BRACE);
        $frameCount = count($files);

        // Rename them sequentially bike_001.jpg etc.
        sort($files);
        $i = 1;
        foreach ($files as $file) {
            $ext = pathinfo($file, PATHINFO_EXTENSION);
            $newName = $extractPath . 'bike_' . str_pad($i, 3, "0", STR_PAD_LEFT) . '.' . strtolower($ext);
            rename($file, $newName);
            $i++;
        }

        // Update database
        $stmt = $pdo->prepare("INSERT INTO bike_360_images (bike_id, folder_path, frame_count) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE folder_path=?, frame_count=?");
        $dbPath = 'assets/uploads/360/bike_' . $bike_id . '/';
        $stmt->execute([$bike_id, $dbPath, $frameCount, $dbPath, $frameCount]);

        echo "Success: Extracted $frameCount frames.";
    } else {
        echo "Failed to open ZIP file.";
    }
}
?>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����