2010-07-23 72 views
1

全部,如何删除阵列中的标题

我有一个PHP应用程序似乎在数组中生成以下标题。我希望删除这些头文件,因此我可以设置新的头文件,例如PDF下载文件。

array(2) { 
    [0]=> 
    string(23) "X-Powered-By: PHP/5.3.1" 
    [1]=> 
    string(23) "Content-type: text/html" 
} 

如何做到这一点,因为这似乎并没有工作:

var_dump(headers_list()); 

header_remove("X-Powered-By"); 
header_remove("Content-type"); 

var_dump(headers_list()); 

回答

1

我觉得行可能做同样的东西你到底想干什么。

header("Content-type: application/pdf"); 
header('Content-Disposition: attachment; filename="sample.pdf"'); 
readfile('/var/www/sample.pdf'); 

感谢

+0

这似乎是工作,但而不是要求用户保存文件,它打印在浏览器中的PDF内容。如何避免这种情况? – Jake 2010-07-23 18:54:14

0

只能修改标题,如果没有输出已发送到客户端呢。因此,var_dump函数会导致header_remove被忽略(因为它显然会向客户端输出文本)。

你也应该看看了输出缓冲功能: http://us3.php.net/outcontrol