<?php
if (isset($_GET['id'])) {
    $id = $_GET['id'];

    // Fetch the CSV file path from your database based on the $id
    include('connection.php'); // Include your database connection code
    $query = "SELECT upload_file FROM add_whatshapp_database WHERE id = $id";
    $result = mysqli_query($conn, $query);

    if ($row = mysqli_fetch_assoc($result)) {
        $csvFilePath = $row['upload_file'];

        // Check if the file exists
        if (file_exists($csvFilePath)) {
            // Set appropriate headers for CSV file download
            header('Content-Type: application/csv');
            header('Content-Disposition: attachment; filename="' . basename($csvFilePath) . '"');
            header('Content-Length: ' . filesize($csvFilePath));

            // Output the file contents
            readfile($csvFilePath);
        } else {
            echo "File not found.";
        }
    } else {
        echo "Record not found.";
    }

    // Close your database connection
    mysqli_close($conn);
} else {
    echo "Invalid request.";
}
?>