����JFIF��`�`�����Viewing File: /home/u820193700/domains/spiti2026im.in/public_html/api/download.php
<?php
// api/download.php
// Proxy endpoint to force download of external online images, bypassing frontend CORS restrictions.

$url = $_GET['url'] ?? '';
$title = $_GET['title'] ?? 'download';

if (empty($url)) {
    http_response_code(400);
    die('Invalid URL parameter.');
}

$is_local = (strpos($url, 'http') !== 0);
$content = null;

// Generate a safe filename
$safe_title = preg_replace('/[^a-z0-9]/i', '_', strtolower($title));
if (empty($safe_title)) {
    $safe_title = 'media';
}

if ($is_local) {
    // --- Local File Routing ---
    $filename = basename($url);
    $local_path = __DIR__ . '/../backend/uploads/' . $filename;
    
    if (!file_exists($local_path)) {
        $local_path = __DIR__ . '/../uploads/' . $filename;
    }
    
    if (!file_exists($local_path)) {
        http_response_code(404);
        die('Local file not found.');
    }
    
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime_type = $finfo->file($local_path);
    
    $extension = 'jpg';
    if ($mime_type === 'image/png') $extension = 'png';
    elseif ($mime_type === 'image/gif') $extension = 'gif';
    elseif ($mime_type === 'image/webp') $extension = 'webp';
    elseif ($mime_type === 'video/mp4') $extension = 'mp4';
    elseif ($mime_type === 'video/webm') $extension = 'webm';
    elseif (stripos($filename, '.mp4') !== false) $extension = 'mp4';

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $safe_title . '.' . $extension . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($local_path));
    
    // Use readfile for large files to avoid memory exhaustion
    readfile($local_path);
    exit;
    
} else {
    // --- Remote File Routing (using cURL for Hostinger compatibility) ---
    if (!filter_var($url, FILTER_VALIDATE_URL)) {
        http_response_code(400);
        die('Invalid URL format.');
    }

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $content = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($content === false || $httpCode !== 200) {
        http_response_code(404);
        die('Failed to retrieve content from remote server.');
    }
    
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime_type = $finfo->buffer($content);
    
    $extension = 'jpg';
    if ($mime_type === 'image/png') $extension = 'png';
    elseif ($mime_type === 'image/gif') $extension = 'gif';
    elseif ($mime_type === 'image/webp') $extension = 'webp';
    elseif ($mime_type === 'video/mp4') $extension = 'mp4';
    elseif ($mime_type === 'video/webm') $extension = 'webm';
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $safe_title . '.' . $extension . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . strlen($content));
    
    echo $content;
    exit;
}
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����