调用文件下载标头后的 PHP 调用函数

发布于 2024-11-02 04:32:07 字数 372 浏览 1 评论 0原文

我有一个创建文件供下载的函数,如下所示:

header("Content-type: application/octet-stream");
header("Content-disposition: filename=file.csv");
print 'hello hello';
exit;

$this->nextFuntion();

我需要在弹出保存对话框后调用“nextFunction”,我在这里看到了各种方法,但它们都与 header('location:') 有关特征。基本上,调用函数的页面包含文件内部的数据。 “nextFunction”将删除页面中的数据并返回消息等。

但我能做的最好的就是让下载工作并且没有任何功能。

I have a function creating a file for download like so:

header("Content-type: application/octet-stream");
header("Content-disposition: filename=file.csv");
print 'hello hello';
exit;

$this->nextFuntion();

I need the "nextFunction" to be called after the save dialogue pops up, I've seen various methods around here but they all have to do with header('location:') feature. Basicly the page where the function is called contains the data that goes inside the file. the "nextFunction" will erase the data form the page and return a message etc.

But the best I can do is get the download to work and no function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南冥有猫 2024-11-09 04:32:07

将其分成两个脚本。第一个将调用该函数,然后重定向到第二个(通过 META 刷新等),第二个将负责发送要下载的文件。

Split this into two scripts. The first will call the function, and then redirect to the second (via a META refresh or the like) which will be responsible for sending the file to be downloaded.

甜心小果奶 2024-11-09 04:32:07

您确定要在下载文件后立即删除该文件吗?如果用户想再次下载它但它不可用,则此功能可能会惹恼他们。我建议设置一个 cron 作业来删除所有早于特定时间的文件。

Are you sure you always want to erase the file immediately after it's downloaded? If the user wants to download it again and it's unavailable, this functionality could annoy them. I'd recommend setting up a cron job to delete all files that are older than a certain time.

初吻给了烟 2024-11-09 04:32:07

我认为你的问题更多地与 nextFunction() 有关,因为 PHP 应该允许你即使在设置标头之后也可以调用函数。

尝试使用仅记录到文件的测试函数或我个人最喜欢的 exec("echo 'HAY HAY' | wall ");

I think your issue is more to do with nextFunction() as PHP should allow you to call functions even after headers are set.

Try it with a test function that just logs to a file or my personal favorite exec("echo 'HAY HAY' | wall ");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文