469,319 Members | 2,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Prompt to "Save As" No Matter What The File Type

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
Jul 17 '05 #1
5 20392
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.
Jul 17 '05 #2
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
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

"Jedi121" <je*********@free.fr.Removethis> wrote in message
news:me********************************@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
Jul 17 '05 #4
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
Jul 17 '05 #5
>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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.