<?php
// download.php फाइल
session_start();

// Check if file parameter is set
if (isset($_GET['file'])) {
    $filename = basename($_GET['file']); // Sanitize filename
    $filepath = 'pdfs/' . $filename;
    
    // Check if file exists
    if (file_exists($filepath)) {
        // Set headers for download
        header('Content-Description: File Transfer');
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filepath));
        
        // Clear output buffer
        ob_clean();
        flush();
        
        // Read the file
        readfile($filepath);
        exit;
    } else {
        // File not found - store error in session
        $_SESSION['pdf_error'] = 'PDF file not found!';
        header('Location: index.php');
        exit;
    }
} else {
    // No file specified
    $_SESSION['pdf_error'] = 'No file specified for download!';
    header('Location: index.php');
    exit;
}
?>