1

好的,这就是我重写它的方式。任何变化?这行得通吗?我在超时的末尾添加了 Javascript。

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
}
?> 
<script type="text/Javascript">
window.setInterval(function()
{
    window.location = "www.moneymovers.com";
}, 5000);
</script>:
4

2 回答 2

1

You can put the location header wherever you want, as long as nothing has been outputted (echo).

If you have outputted something, you can output something like this to redirect :

<script type="text/javascript">
    window.location = "www.example.com";
</script>

EDIT :

In your case, it is not possible to do what you're looking for, as far as I know. You will have to manage this case in the caller page. The Javascript will not be called because you've modified the Content-Disposition.

于 2013-06-18T19:35:54.540 回答
1

您无法下载然后进行标头重定向。客户端一看到标头就会重定向,这意味着下载将无法进行。但是你也不能在下载后输出标题,因为那样重定向就不会发生。不管怎样,它是行不通的。

我建议在不同的级别上执行此操作。例如,当用户单击下载链接时,让一些 JavaScript 在新选项卡/窗口中开始下载,然后重定向到当前选项卡中的所需位置。

于 2013-06-18T20:36:07.013 回答