0

I want the user be forced to download a file, then be redirected to another page. There was a lot more code, but in debugging this issue I have cut everything down to the following snippet(assume $link has been defined):

ob_start();
header("Refresh: 0; URL=".$link);
header("Content-Disposition: attachment; filename='test.doc'");
ob_end_flush();
exit;

This works in Firefox, but not in Chrome. If I comment out the content-disposition header, the redirect work will work in Chrome. As of right now, this makes Chrome force the download, but it will not execute the redirect. In Firefox, the download is forced, and the page redirects. Which is the desired effect. I have tried doing this with and without the ob_start/ob_end_flush statements. I have tried using die() instead of exit. I have tried different syntaxes for the same header statements.

Unfortunately, using header("Location: $link") will not work for this situation, because it will not allow the download to be executed. This is true in Firefox and Chrome.

I'm hoping it's something dumb that I'm missing. But any insight would be greatly appreciated.

Please let me know if I can offer clarification on this issue.

leguiato
  • 1
  • 1
  • you can try to use this: http://stackoverflow.com/questions/13908023/php-header-content-disposition-attachment-then-location-some-url – swidmann Nov 03 '15 at 15:37
  • Thanks for the help. I have to decided to use javascript to handle the redirect and php for the IO. – leguiato Nov 04 '15 at 12:57
  • glad you found a working solution, maybe you can post it as an answer? – swidmann Nov 04 '15 at 13:00

0 Answers0