Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中仅回显要下载的指定文本_Php_Http Headers_Download - Fatal编程技术网

如何在PHP中仅回显要下载的指定文本

如何在PHP中仅回显要下载的指定文本,php,http-headers,download,Php,Http Headers,Download,我有一些php代码,看起来像: header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$filename"); header("Content-Type: application/octet-stream; "); header("Content-Transfer-Encoding: bina

我有一些php代码,看起来像:

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; "); 
header("Content-Transfer-Encoding: binary");
echo 'test';
在此块之后,将加载视图以呈现要显示的页面的html


问题是页面上的所有html都是文件下载的一部分。如何恢复正常的浏览器输出,以便只将回显文本发送到文件下载?

在标题内容之前回显。因此,您正在寻找一种方法来阻止脚本在特定点之后执行代码?试试看。@Vincius-对不起,这没有道理。我想在下载中包含回显文本。只是不是所有的事情。@hanzi-在这种情况下不起作用。网页的其余部分在文件下载后显示,因此它仍然包含在文件中。看起来您正在寻找类似于
内容类型的内容:multipart/mixed电子邮件,但用于web。不幸的是,它并不存在。另一种探索途径是,但客户端浏览器可能不支持。