开发者

PHP & WordPress: headers already sent - what to do? [duplicate]

This question already has answers here: How to fix "Headers already sent" error in PHP (11 answers) 开发者_如何学JAVA Closed 9 years ago.

I'm working on a WordPress template where files of my FTP to get listed. If I click on a file I call d.php (d=download) where I simply pass along the path of the file and I want to force a download with

header('Content-Disposition: attachment; filename="'. $file .'"');

This is not working for me, because the browser keeps telling me:

Warning: Cannot modify header information - headers already sent by (output started at /clientdata/n5200-2-dynamic/a/l/mydomain.net.au/www/wp-content/themes/mytheme/d.php:25) in /clientdata/n5200-2-dynamic/a/l/mydomain.net.au/www/wp-content/themes/mytheme/d.php on line 45

Any idea what I could do here? The d.php doesn't even include any WordPress specific stuff (get_header() or get_footer()) - it's just a simple php file in the template directory of my theme. Any idea what I could do here?

thank you


When using the header() function in PHP, it must be sent before any output is sent. This means that it must be executed before the <html> tag. This will mean including it in a procedurally earlier script.


I believe WordPress routes everything thru index.php, so technically you are wrapped inside of the WordPress stuff.

Regardless, something is sending the headers before you are. This could be white space, PHP output, or indeed the actual headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜