Header Redirect in download page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Header Redirect in download page

Post 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
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

never seen URL in location before? you sure its not just

Code: Select all

header("Location: getApp.php?id=$id");
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Oh, haha. Just copied what he had. :P
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post 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!
Post Reply