composer package updates
[openemr.git] / vendor / mpdf / mpdf / data / out.php
blob4d07704f03fc77d00ced491a44ae0ee2022ba650
1 <?php
3 $path = '../tmp/';
5 $tempfilename = $_REQUEST['filename'].'.pdf';
7 if (strstr($tempfilename,'/') || strstr($tempfilename,'\\')) {
8 throw new MpdfException('Output filename can not not contain \ or /');
11 $name = $_REQUEST['opname'];
12 $dest = $_REQUEST['dest'];
14 if ($tempfilename && file_exists($path . $tempfilename)) {
15 // mPDF 5.3.17
16 if ($dest === 'I') {
17 if (PHP_SAPI != 'cli') {
18 header('Content-Type: application/pdf');
19 header('Content-disposition: inline; filename="' . $name . '"');
20 header('Cache-Control: public, must-revalidate, max-age=0');
21 header('Pragma: public');
22 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
23 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
25 } elseif ($dest === 'D') {
27 if (headers_sent()) {
28 throw new MpdfException('Some data has already been output to browser, can\'t send PDF file');
31 header('Content-Description: File Transfer');
32 header('Content-Transfer-Encoding: binary');
33 header('Cache-Control: public, must-revalidate, max-age=0');
34 header('Pragma: public');
35 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
36 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
37 header('Content-Type: application/force-download');
38 header('Content-Type: application/octet-stream', false);
39 header('Content-Type: application/download', false);
40 header('Content-Type: application/pdf', false);
41 header('Content-disposition: attachment; filename="' . $name . '"');
44 $filesize = filesize($path.$tempfilename);
45 if (empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
46 // don't use length if server using compression
47 header('Content-Length: ' . $filesize);
50 $fd = fopen($path . $tempfilename, 'rb');
51 fpassthru($fd);
52 fclose($fd);
53 unlink($path . $tempfilename);
55 // ====================== DELETE OLD FILES - Housekeeping =========================================
56 // Clear any files in directory that are >24 hrs old
58 $interval = 86400;
59 if ($handle = opendir(dirname($path.'dummy'))) {
60 while (false !== ($file = readdir($handle))) {
61 if (((filemtime($path.$file)+$interval) < time()) && ($file != "..") && ($file != ".") && substr($file, -3)=='pdf') {
62 unlink($path.$file);
65 closedir($handle);
67 exit;