二进制输出而不是PDF文件的下载对话框

时间:2014-04-02 13:05:10

标签: php download

下面的代码显示了二进制数据,而不是显示pdf文件的下载对话框。

我做错了什么?

    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/octet-stream');
    header("Content-Disposition: attachment; filename=\"".basename($filepath)."\";" ); 
    header("Content-Transfer-Encoding: binary"); 
    header("Content-Length: ".filesize($filepath)); 
    readfile($filepath);

exit;

already tried application/pdf but no luck !

1 个答案:

答案 0 :(得分:1)

application / octet-stream 替换为 application / pdf ,然后重试。