out.php 2.2 KB

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