Re: Force Download Link Files?

From: Date: Thu, 17 Apr 2003 21:03:45 +0000
Subject: Re: Force Download Link Files?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144346@lists.php.net to get a copy of this message
----- Original Message ----- From: "Poon, Kelvin (Infomart)" <kpoon@infomart.ca> To: <php-general@lists.php.net> Cc: <spideyyy@hotmail.com> Sent: Thursday, April 17, 2003 2:26 PM Subject: [PHP] Force Download Link Files? > Hi all, > > I have some link to some files (.jpg, .doc, .xls) and normally when you > "left" click on it, it would open the file. And if you want to download the > file you would have to "right" click and "save as.." I want to enable my > user to be able to download these files by just "left" clicking on the link. > > I have tried many things, I try linking it to a new php page and sent in > some headers, my code: > > <? > header("Content-type: application/octet-stream"); > header("Content-Disposition: filename='ABC.gif'"); > ?> > > > However, it didn't work. Then someone told me to try this, > > <? > header("Content-type: application/octet-stream"); > header("Content-Disposition: filename='ABC.gif'"); > print "bal bla bla"; > ?> > > I did, this time it lets me save the ABC.gif (an dialogue box comes up and > ask me to open or save), and after saving it, when I try to open my file, I > see a big red X (the file is probably empty). I don't know why. Can anyone > please help me? THanks a lot > > Kelvin I believe the example was meant to show you that you need to send data to the output buffer (ie. print it to the screen) after you set the headers.. header("Content-type: application/octet-stream"); // invoke file save dialog header("Content-Disposition: filename='ABC.gif'"); // set default filename in dialog readfile("image.gif"); // send file to output buffer This is the bare minimum. Since the browser is responsible for header parsing and actions, and there are different versions of headers, there are a number of pitfalls to watch out for that you will need to research in order to build a competent download script. - Kevin

« previous php.general (#144346) next »