使用php制作可下载的文本文件,然后重定向

使用php制作可下载的文本文件,然后重定向,php,download,Php,Download,我正在制作一个脚本来创建一个临时文本文件来下载并重定向回一个页面,但是我有一个问题,即发送头信息后的所有内容都会在下载时进入文本文件 <?php session_start(); include('session.php'); //echo $login_session; require_once "getconnected.php"; $connection = getConnected(); header('Content-Type: application/octetstream;

我正在制作一个脚本来创建一个临时文本文件来下载并重定向回一个页面,但是我有一个问题,即发送头信息后的所有内容都会在下载时进入文本文件

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();

header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
Hello, world.
<script>

window.location.href="/usercp/monitorproducts.php";

</script>
<?



?>
一旦您使用“header”表示您正在发回一个文件,客户端就会这样处理它


web服务器正在发回一个响应头,告诉浏览器它将要接收一个文件。

哇,我找到了一个有效的解决方案

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();
header( "refresh:5;url=/usercp/monitorproducts.php" );
header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
hello world

可能的重复我认为一个web请求不可能得到多个答案。您将file.txt下载中的内容放在哪里?