This is a discussion on Prompt to "Save As" No Matter What The File Type within the PHP Language forums, part of the PHP Programming Forums category; What I want is to have a link to a file (it could be a .zip, .exe, .jpg, ..txt or ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
..txt or even .html) and when the user clicks on it they are prompted with the Save As box, as opposed to it opening in the browser. I think I need to do something like: $fp = fopen($filetooutput, "rb"); $thefile = fread($fp, filesize($thefiletooutput)); header("Content-type: ???/???"); not sure what to put instead of the ??? echo $thefile; If anyone can help that would be much appreciated Richie |
|
|||
|
Richie a écrit le 27/01/2004 :
> What I want is to have a link to a file (it could be a .zip, .exe, .jpg, > .txt or even .html) and when the user clicks on it they are prompted with > the Save As box, as opposed to it opening in the browser. > I think I need to do something like: > > $fp = fopen($filetooutput, "rb"); > $thefile = fread($fp, filesize($thefiletooutput)); > header("Content-type: ???/???"); not sure what to put instead of the ??? > echo $thefile; > > If anyone can help that would be much appreciated > Richie Don't mess up the Content-type header, consider using : <?php header("Content-disposition: attachment; filename=my_name_of_the_file"); ?> But look at Google for know issues on some browser versions. |
|
|||
|
Richie wrote:
> > What I want is to have a link to a file (it could be a .zip, .exe, .jpg, > .txt or even .html) and when the user clicks on it they are prompted with > the Save As box, as opposed to it opening in the browser. > I think I need to do something like: > > $fp = fopen($filetooutput, "rb"); > $thefile = fread($fp, filesize($thefiletooutput)); > header("Content-type: ???/???"); not sure what to put instead of the ??? > echo $thefile; Google for content-disposition header. Set it to "attachment", I think. That doesn't work on some browsers, though. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |
|
|||
|
"Jedi121" <jedi121news@free.fr.Removethis> wrote in message news:mesnews.dd047d41.6e4253bc.504.2689@free.fr.Re movethis... > Richie a écrit le 27/01/2004 : > > What I want is to have a link to a file (it could be a .zip, .exe, .jpg, > > .txt or even .html) and when the user clicks on it they are prompted with > > the Save As box, as opposed to it opening in the browser. > > I think I need to do something like: > > > > $fp = fopen($filetooutput, "rb"); > > $thefile = fread($fp, filesize($thefiletooutput)); > > header("Content-type: ???/???"); not sure what to put instead of the ??? > > echo $thefile; > > > > If anyone can help that would be much appreciated > > Richie > > Don't mess up the Content-type header, consider using : > <?php > header("Content-disposition: attachment; > filename=my_name_of_the_file"); > ?> > But look at Google for know issues on some browser versions. > > That worked great, thanks. Hopefully on the few browsers that it doesn't work on, it'll just open the file in the browser as normal Richie |
|
|||
|
Richie wrote:
> What I want Perhaps unwittingly, you've made known the root of the perceived problem already: what you want and what someone else wants aren't necessarily one and the same. > is to have a link to a file (it could be a .zip, .exe, .jpg, .txt or > even .html) and when the user clicks on it they are prompted with the > Save As box, as opposed to it opening in the browser. (a) What "Save As box"? My browser didn't come with one. ;-) (b) What makes you think that you know how I ought to deal with files? (c) Which piece of software would you have me open an HTML file with, if not my browser? > header("Content-type: ???/???"); not sure what to put instead of the ??? The file's media type perchance? Here's the authoritative registry for Internet media types: ftp://ftp.isi.edu/in-notes/iana/assi...s/media-types/ And you'll see that Content-Disposition -- a non-HTTP/1.1 header, defined in the experimental RFC1806 -- has been put forward as a suggestion in other followups, which have rightly warned against sending illegitimate Content-Type headers. If your wish is to convey presentational information, this is the logical way. But sending this header, with a disposition type of attachment, does *not* guarantee that a client will ask the user what she wants done with the file; not being part of the HTTP/1.1 draft standard, conforming applications aren't obliged to act upon Content- Disposition headers. I reckon RFC1806's intention is *not*, without a smidgen of a doubt, to provide servers with the mechanism to "force" particular actions on clients. Is that not your inference too? -- Jock |
|
|||
|
>doesn't work on some browsers, though.
It should not work in IE 4.x browsers and below. ____________________________________ Wil Moore III, MCP | Integrations Specialist | Senior Consultant DigitallySmooth Inc. | Quick Site Studio |