Downloading Files

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
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Downloading Files

Post by Clukey »

I have set up a download page for a user to download a file from my website, but it has stopped working properly (I think because of a new version of IE). Right now I am using application/force-download to download a Dreamweaver Extension (application type: application/x-mmxp). Is there any other way that I could do this to make it a bit more reliable? Thanks
arkady
Forum Newbie
Posts: 23
Joined: Sun Sep 17, 2006 9:34 pm

Re: Downloading Files

Post by arkady »

Clukey wrote:I have set up a download page for a user to download a file from my website, but it has stopped working properly (I think because of a new version of IE). Right now I am using application/force-download to download a Dreamweaver Extension (application type: application/x-mmxp). Is there any other way that I could do this to make it a bit more reliable? Thanks
Is the file displaying inline (ie. in your browser)? Or are you getting nothing happening?
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Re: Downloading Files

Post by Clukey »

arkady wrote: Is the file displaying inline (ie. in your browser)? Or are you getting nothing happening?
It is displaying inline
arkady
Forum Newbie
Posts: 23
Joined: Sun Sep 17, 2006 9:34 pm

Post by arkady »

I've found that the following works fine for myself in both ie & firefox

Code: Select all

header("Pragma: public");
header("Expires: " . gmdate('D, d M Y H:i:s') . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Length: " . $my_filesize);
header("Content-Type: application/" . $file_type[$stated_file_type]);
header("Content-Disposition: attachment; filename='".$filename."'");
header("Content-Transfer-Encoding: binary");  // assuming its a binary file of course
Hopefully this comes in handy for you
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

Thanks, that works, but is there any way to do this and hide the location of the file?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

By going through a script you are hiding the location.
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

Right, but in firefox when it brings up a download file dialog box it shows the relative location to the file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That dialog box is on your local system, not on the server. You can't really hide much from the user, especially when doing stuff over a browser.
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post by Clukey »

Well then is there any way to duplicate the file into another folder temporarily and download it from there?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's no reason to, the path the user sees has no bearing on the file the server is sending, but on what their browser chooses to show them with respect to what your script gives it. I'm not going to repeat this again.
Post Reply