Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force browser to save a GIF but not open it.

Status
Not open for further replies.

ttest

Programmer
Jun 28, 2000
38
US
I have a cgi script that generate html content on the fly. I want the browser to prompt the file save dialog instead of showing the html content when user click on the cgi hyperlink. The problem is, how do I force the browser to prompt the file save dialog?

I have tried to send the header 'Content-Type: application/octet-stream' or 'Content-Type: application/x-msdownload' to the browser, but the browser still show the html instead of prompt the file save dialog.

Any other idea?

ttest
thum@starwarsfan.com

 
After reading the HTTP RFC document, I have found the answer to this question. First, IE and Netscape browsers react differently to the Content-Type: application/octet-stream header.

For Netscape 4.x and 6.x, when it encounter this header, it will show the 'Save' dialog.

For IE, when it encounter this header, it will try to identify the content by itself. If the content is a html document, IE will still display the html. To force IE to show the 'Save' dialog, you have to send 2 headers. First, send the Content-Type: application/octet-stream header. Then send the Content-Disposition: attachment; filename="fname.ext". Substitute the fname.ext with the filename you want the user to save as.

ttest
thum@starwarsfan.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top