Simple file link or button doesnt work

P

pd

guys,

in my web app, i have a simple download button and a href which points
to a file on my server, when the user clicks on the button or the
link, the file should simply be downloaded to the users machine. now
this file is a postgres backup file with the .backup extension.

now when i use the button, in FF the file download button pops up and
i can save the file, i can also right click the href and go save link
as. and it works fine.

but when i use the button or link in IE, it simply opens up the file
in IE as text and displays a bunch a garbage. now the user needs to be
able to download the file and not view it. also on the href link, when
the right clicks and goes save target as IE automatically adds
the .html extension to the file. now i dont have the .backup extension
in my registered file types.

just to end, my href is, <a href="http://localhost:8080/Backup/
Today.backup">Download</a> and the button is,
<input type="button" value="Download" onclick="location.href('http://
localhost:8080/Backup/Today.backup')">

please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.
 
L

Lee

pd said:
please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.

That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.


--
 
C

ChrisHolland@InternetBrands

It's true that browsers have various sets of "default behaviors" for
various mimetypes:

- some known mimetypes will by default be displayed inside the
browser.
- some known mimetypes will by default be downloaded to the desktop.
- when no mime type is sent, and the browser doesn't recognize the
file type, then anything could happen, and i suspect that's what's
happening with your backup file.

You can override the download vs show-in-browser "default behavior",
thru the "content-disposition" http header field:

http://www.ietf.org/rfc/rfc2183.txt

Try configuring your http server so that .backup files will have a
correct mime type if one is defined, but more relevantly, try to make
sure your server sends an additional HTTP Header:

Content-Disposition: attachment; filename=MYFILE.backup

Flickr.com has some good examples of overriding a browser's default
behavior of loading images inside the browser window and forcing a
download thru the Content-Disposition header. If you have a flickr
account, look at a picture's "all sizes" page, and click the
"Download" link. It's a simple HREF Anchor Tag, but the HTTP Response
does set the Content-Disposition header, here's an excerpt from a
response to a click on one of my images:

HTTP/1.0 200 OK
Date: Fri, 01 Jun 2007 08:12:34 GMT
Server: Apache/2.0.52 (Red Hat)
Content-Disposition: attachment;
filename=516875174_4be52f4dbd_b.jpg <---- LOOK RIGHT HERE
Pragma: no-cache
Expires: 0
Last-Modified: Sun, 27 May 2007 23:30:50 GMT
Accept-Ranges: bytes
Content-Length: 396060
Content-Type: image/jpeg <--- ALWAYS A GOOD IDEA TO SET PROPER
MIMETYPE AS Content-Type header value
X-Cache: MISS from photocache3.flickr.mud.yahoo.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top