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

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-27-2004
Richie
 
Posts: n/a
Default 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


Reply With Quote
  #2 (permalink)  
Old 01-27-2004
Jedi121
 
Posts: n/a
Default Re: Prompt to "Save As" No Matter What The File Type

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.


Reply With Quote
  #3 (permalink)  
Old 01-27-2004
Shawn Wilson
 
Posts: n/a
Default Re: Prompt to "Save As" No Matter What The File Type

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
Reply With Quote
  #4 (permalink)  
Old 01-27-2004
Richie
 
Posts: n/a
Default Re: Prompt to "Save As" No Matter What The File Type


"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


Reply With Quote
  #5 (permalink)  
Old 01-27-2004
John Dunlop
 
Posts: n/a
Default Re: Prompt to "Save As" No Matter What The File Type

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
Reply With Quote
  #6 (permalink)  
Old 01-28-2004
laidbak
 
Posts: n/a
Default Re: Prompt to "Save As" No Matter What The File Type

>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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:26 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0