PHP &WordPress:标题已发送 - 该怎么办? [英] PHP & WordPress: headers already sent - what to do?
问题描述
我正在开发一个 WordPress 模板,其中列出了我的 FTP 文件.如果我点击一个文件,我调用 d.php (d=download) 在那里我只是传递文件的路径,我想用
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:
警告:无法修改标头信息 - 标头已发送(输出开始于/clientdata/n5200-2-dynamic/a/l/mydomain.net.au/www/wp-content/themes/mytheme/d.php:25) 在/clientdata/n5200-2-dynamic/a/l/mydomain.net.au/www/wp-content/themes/mytheme/d.php 第 45 行
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
知道我可以在这里做什么吗?d.php 甚至不包含任何 WordPress 特定的东西(get_header() 或 get_footer())——它只是我主题模板目录中的一个简单的 php 文件.知道我可以在这里做什么吗?
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?
谢谢
推荐答案
在 PHP 中使用 header()
函数时,必须在发送任何输出之前发送它.这意味着它必须在 标签之前执行.这意味着将其包含在程序较早的脚本中.
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.
这篇关于PHP &WordPress:标题已发送 - 该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!