Page 1 of 1

Header Redirect in download page

Posted: Mon Jun 06, 2005 1:57 pm
by drgnjucr
Hi All.
I have been fumbling with my code in order to make a download page that works in both IE and FF. I've figured out, that the problem I'm encountering is because of my "header(Refresh:" function which should redirect to the actual download page. It works fine in FF, however in IE, IE tries to download the refresh url location instead of the actual file??
What I've done, is have a page with downloads. You click on the desired download and are then taken to a "confirmation" page, "your download will begin...blah, blah". If it doesn't, click here.. " That kind of thing. On that confirmation page, I used the "header(Refresh:1 url=" in order to create that effect. Works like a champ in FF, but IE tries the url. If I click on the link, "here" if the download doesn't begin (which accesses the download page directly) it works fine in IE??

Any help would be appreciated.

Here is some of my code:

getApp_ok.php

Code: Select all

header("Refresh: 1; URL=getApp.php?id=$id");
getApp.php

Code: Select all

$theFile = "$path" . "$appName"; # combine the path and file
   header("Cache-Control: ");# leave blank to avoid IE errors
   header("Pragma: ");# leave blank to avoid IE errors 
   header("Content-Type: ".filetype($theFile));
   header("Content-length: ".filesize($theFile));
   header("Content-Disposition: attachment; filename=\"".$appName."\"");
   @readfile("$theFile");
*My variables are coming from a MySQL db.

Thanks everyone!
-Mike

Posted: Mon Jun 06, 2005 5:41 pm
by Skara
Don't use header Refresh. Use:

Code: Select all

header("Location: URL=getApp.php?id=$id");
other than that, I don't know.

Posted: Mon Jun 06, 2005 5:45 pm
by John Cartwright
never seen URL in location before? you sure its not just

Code: Select all

header("Location: getApp.php?id=$id");

Posted: Mon Jun 06, 2005 5:57 pm
by Skara
Oh, haha. Just copied what he had. :P

Posted: Tue Jun 07, 2005 9:58 am
by drgnjucr
If I just use "header(location:" the confirmation page will not display. The download will just begin. Unless I'm not coding it correctly?

I've tried placing the "header(location:" bit on my "confirmation page" and by doing that, the page won't display, or print. the download just begins. I tried putting a sleep in, or even a meta refresh and that does not work either.

The only way I have been able to sucessfully display the download confirmation page, was to use the "header(refresh"..which causes the IE problem.
For now, I've just disabled the auto download piece if IE is being used so the user would have to click the link "if your download does not begin, click here"

I'd like to fix it, but need some help. :)

Thanks for the replies!