out.php 2.2 KB

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