PHP强制IE下载文件

时间:2014-02-18 03:12:56

标签: php

(的download.php)

......(other HTML code)......
$filepath = '/storage/uploaded_files/'.$thisSysName;
header("Content-Type: application/force-download"); 
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Disposition: attachment; filename="'.basename($filepath).'"'); 
readfile($filepath);
......(other HTML code)......

对话框确实在IE上显示,但该文件的内容是HTML(download.php)的内容。

怪异。

1 个答案:

答案 0 :(得分:3)

  

......(其他HTML代码)......(第1行)

在您已经向其发送内容后,您无法将标题发送到浏览器。换句话说,标题是浏览器应该接收的第一件事。

For more information refer to this answer