强制文件下载PDF'打开'框中说它是一个Firefox文件?

时间:2013-05-13 04:49:58

标签: php force-download

我正试图强制下载PDF文件,一切正常。唯一的问题是当它显示一个"下载框"它说它是一个" Firefox文件"实际应该说" Adob​​e Acrobat Document"。看图像,下面是我正在使用的代码

1)从gmail强制下载框,工作正常

enter image description here

2)从我的应用程序强制下载框,其中包含" Firefox Document"

enter image description here

  header("Pragma: public"); 
  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
  header("Content-Type: application/pdf"); 
  header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); 
  header("Content-Transfer-Encoding: binary"); 
  header("Content-Length: ".filesize(getcwd().$file)); 

  readfile(getcwd().$file); 

2 个答案:

答案 0 :(得分:1)

适用于搜索相同问题的所有人。

TS解决方案:

添加exit @ the end(由于某些原因,firefox需要这个)

header("Content-Type: application/pdf");
echo $pdf;
exit;

答案 1 :(得分:0)

尝试使用

Header('Content-Type: application/octet-stream');

而不是

Header("Content-Type: application/pdf");