gpt4 book ai didi

php - php 提供下载后刷新

转载 作者:行者123 更新时间:2023-11-28 02:46:19 25 4
gpt4 key购买 nike

第 1 页链接到第 2 页。第 2 页使用以下代码提供下载:

header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/pdf');
readfile($file);
header("location: mainpage.php");

结果是用户“停留”在第 1 页,但可以下载。

如何进行设置,以便用户保留在第 1 页,但在提供下载后刷新。

我不懂 JavaScript,所以我希望有一个纯粹的 PHP 解决方案。

最佳答案

在我看来,我认为您根本不需要刷新 page1。您应该能够通过 page1 中的链接强制下载。见下文:

带有链接的Page1.php

<a href="http://www.domain.com/page2.php?pdf=name-of-pdf">Download PDF</a>

Page2.php

$filename = $_GET['pdf'] . '.pdf';

header('Content-type: application/pdf');
header("Content-disposition: attachment; filename= '$filename'");
header("location: $filename");

这将允许您在停留在第 1 页时开始下载。

希望这就是您的想法。

关于php - php 提供下载后刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11804543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com