PHP HTTP下载标题

时间:2015-10-23 22:16:29

标签: php http download header

我正在尝试使用PHP生成HTML文件并强制浏览器下载它。问题是,即使我生成具有未知扩展名的文件,例如" .mail"该文件显示在浏览器窗口中。我试图重写HTTP标头,但似乎服务器(PLESK)忽略了它们: 这是我的PHP代码:

<?php 
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="mail.html"');
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//print_r($_POST);
switch ($_POST['radios']){
    case 1:

        include("1.include");

        print($_POST["editor1"]);

        include("1-foot.include");
        brake;
    case 2:
        brake;
    case 3:
        brake;
    case 4:
        brake;
}

?>

Firebug向我展示了这个标题:

Connection  
Keep-Alive
Content-Type    
text/html
Date    
Fri, 23 Oct 2015 22:06:41 GMT
Keep-Alive  
timeout=5, max=100
Server  
Apache
Transfer-Encoding   
chunked
X-Powered-By    
PleskLin
Quelltext anzeigen
Accept  
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding 
gzip, deflate
Accept-Language 
de,en-US;q=0.7,en;q=0.3
Cache-Control   
no-cache
Connection  
keep-alive
Cookie  
_pk_id.1.974f=82b4d2cf248e9b40.1420714194.2.1421423646.1420714194.; __atuvc=1%7C1%2C1%7C2
Host    
**********************
Pragma  
no-cache
Referer 
**********************
User-Agent  
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101 Firefox/41.0

1 个答案:

答案 0 :(得分:2)

搞定了:) <?php>之前有1个空格导致标题没有被发送:) 感谢