在php中下载文件后重定向任何页面

在php中下载文件后重定向任何页面,php,Php,我的代码是: readfile('cls_ref.csv'); fclose($fp); $file_type = 'octet-stream'; $file_name = "cls_ref_" . date('m-d-Y H:i'); $file_ending = "csv"; header("Content-Type: application/$file_type; charset=utf-8"); header("Content-Disposition: attachment; f

我的代码是:

readfile('cls_ref.csv');
fclose($fp);
$file_type   = 'octet-stream';
$file_name   = "cls_ref_" . date('m-d-Y H:i');
$file_ending = "csv";
header("Content-Type: application/$file_type; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_name.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
header("Location:index.php");
我想在下载后重定向到
index.php
,但它在下载前是重定向的

我编写了一个代码
标题(“Location:index.php”)位于文件末尾,但在
下载文件


有解决方案吗?

10秒后进行元刷新怎么样:

print "<meta http-equiv=\"refresh\" content=\"10;URL=index.php\">";
print”“;

这是行不通的!!它写在文件末尾的
.csv
文件中。看起来他正在输出文件的内容。打印任何东西都会将其附加到文件中,从而破坏文档。我认为您不能重定向到要打印文件的PHP文件上。可能尝试在有下载链接的页面上使用javascript重定向?或者重定向到另一个php页面,在该页面开始下载并使用meta标记重定向。在页面上实现JQuery。使链接可能重复到新窗口中打开的文件,然后使用javascript,您可以使用
location.href=“index.php”