[thelist] Browser detection and save file as

Glenn Hunt ghunt at sympatico.ca
Tue Sep 18 13:16:37 CDT 2001


I went through this recently, although we used a script to process the
file instead of giving direct access. What we had to do was to have in
the header the following. I'm not sure how it would translate to PHP:

<cfheader name="Content-disposition" value="inline;
filename=<filename>">
<cfcontent type="application/x-unknown" file="<filename>">

Basically, the first line tells the browser that it is receiving a file,
not an html document. The second line tells the browser that the MIME
type of the file is "unknown". This forces most browsers to prompt to
save the file.

There was only two caveats:

1. IE (various version) will "sniff" the file to see if it recognizes
it. If it does recognize it, then it will process it, ignoring the MIME
type. Nothing can be done about this.

2. IE 5.5 SP1 will incorrectly offer to save the file using the name of
the download page, instead of the file name provided in
"Content-disposition". Again, there is no workaround for this.

Your only other options are to use a Java type download manager.

Glenn Hunt
ghunt at hds.ca


-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org] On Behalf Of Kevin Martin
Sent: Tuesday, September 18, 2001 11:55 AM
To: thelist at lists.evolt.org
Subject: [thelist] Browser detection and save file as


A client wished for an upload-download page; I borrowed some PHP code to

invoke ftp, which worked fine for the upload but it fell over on the 
download side.  I hacked the PHP to present http links to the 
available files, so it works both ways now.  But...  it requires the 
user to be clueful enough to right-click (or whatever the equivalent is
on 
a Mac!) in order to do a 'save file' or 'save link' or 'save this 
link as' depending on the browser she's using.

So... I was wondering if anyone had a clever trick that would force all
(or even most) browsers to download a file rather than opening a file?
I have complete control over the server (Apache), if that helps.

Failing that, a pointer to some pre-tested code to detect the browser
and 
platform would be a godsend -- few things shake a user's confidence
worse 
than asking her to "right-click" with a Mac mouse.

<tip type="Warning!" author="digger">
IE 5 on MacOS 9.1 does NOT like self-signed OpenSSL certificates. It
will hang your Mac hard if you even try to view the site.  Be warned!
</tip>


---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to: http://lists.evolt.org
Workers of the Web, evolt ! 








More information about the thelist mailing list