<?php
// Get the filename from the query string
$filename = basename($_GET['file']);  // Use basename() to avoid path traversal

// Define the directory where files are stored
$filepath = '../uploads/' . $filename;

// Check if the file exists in the designated directory
if (file_exists($filepath)) {
    // Set the appropriate headers for downloading the file
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . urlencode($filename) . '"');
    
    // Output the file content
    readfile($filepath);
    exit;
} else {
    // If the file doesn't exist, return an error message
    echo "File not found!";
    exit;
}
?>
