Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
913 B
3
Indexable
Never
public function downloadTemplate()
    {
        $_REQUEST['file'] = './Resource/dieutradanso.pdf';
        if (isset($_REQUEST["file"])) {
            $file = urldecode($_REQUEST["file"]); 
            $filepath = "" . $file;
            if (file_exists($filepath)) {
                header('Content-Description: File Transfer');
                header('Content-Type: application/pdf');
                header('Content-Disposition: attachment; filename="' . basename($filepath) . '"');
                header('Expires: 0');
                header('Cache-Control: must-revalidate');
                header('Pragma: public');
                header('Content-Length: ' . filesize($filepath));
                flush(); 
                readfile($filepath);
                die();
            } else {
                http_response_code(404);
                die();
            }
        }
    }