<?php
include './drawers/php/config.php';
session_start();
$token = $_SESSION['token'];

$query_select_submissions = mysqli_query($conn, "SELECT * FROM `submissions` WHERE `token` = '$token'");
if (mysqli_num_rows($query_select_submissions) > 0) {
    $query_row_sub = mysqli_fetch_array($query_select_submissions);
    $pdf = $query_row_sub['pdf_upload_path'];
}

$file = './generate/'.$pdf.'';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename="' . basename($file) . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
} else {
    echo 'File not found.';
}
