我正在使用此代码下载pdf文件。它在chrome中工作得很好,但在mozila中它会创建.htm文件。任何人都可以帮我解决这个问题。
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
readfile('phpToPDF/examples/pdf/'.$filename);
答案 0 :(得分:3)
您需要终止当前脚本。这就是你在Mozilla上获得.htm扩展的原因。 使用exit();在代码的最后。
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
readfile('phpToPDF/examples/pdf/'.$filename);
exit();