开发者

PHP Headers - Content & Location [duplicate]

开发者 https://www.devze.com 2023-04-12 17:06 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Download a file and redirect…or alternative
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Download a file and redirect…or alternative

Basically, we have a PHP file which outputs a file type using PHP headers.

We want it to work like this:

User clicks link, page opens, 开发者_StackOverflow中文版download prompt comes up and then the page that prompted the download (the main php page) redirects to another page...

How can I go about doing this? I want it to only redirect once the download prompt has been delivered to the user.

So.. sort of a thank you page.

Can this be done like so:

header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public', false);
header('Content-Description: File Transfer');
header('Content-Type: '.$type);
header('Accept-Ranges: bytes');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
/* sleep for say 3 seconds.. */
header('Location: thankyou.php');
exit();

This code was purely written as an example, but how can we create something like this?

So the download prompt pops up, wait say 3 seconds, and then direct the origin page to a thank you page.


HTTP headers are output all at once (save for chunked sending, though I'm a bit hazy on whether HTTP allows that for headers).

This question looks to be similar.


header('Location: thankyou.php');

Will kill your download,

If you sleep you stop every thing and the browser wont receive the file it will just redirect to thank-you.php

0

精彩评论

暂无评论...
验证码 换一张
取 消