开发者

Header redirect after download

I am new to PHP and learning it step by step. Well I've a download page that I want to be redirected after the download has been completed.

header('Content-type: application/octet-stream');                 
header('Content-Disposition: attachment; filename="dlink.pdf"');                  
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");                  readfile('dlink开发者_如何学C.pdf');   
header("refresh: 2; auto_works.html");
exit;

This is my download code enclosed within the PHP tag. How can I achieve my directive ? Please help. Could you also mention to me where am I supposed to write the line of code

Thanks


You can't redirect after the download is complete. The webserver (which would do the redirect) doesn't know when the download is complete. There are ofcourse ways, but they're difficult and not worth it.

You 'should' redirect after the download started.


Try to set

header("Location: auto_works.html");exit; 

instead of

header("refresh: 2; auto_works.html"); exit;


This is not possible with pure HTTP. Either you respond to a user request with a download response or a redirect response.

Of course you can do some client-side scripting and do two things at once - e.g. open a pop-up window leading to file download and load a new page in the original window at the same time. But I discourage you to do this, because it's not user-friendly and might not work with some configurations at all.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜