tags:

views:

148

answers:

4

I have a website from which I want to enable browser users to download an exe.

I am testing it with a very simple HTML file which I load into the web browser with "File>Open". The "body" looks something like this:

<body>
<a href="http://www.example.com/myprogram.exe" target="_self">click to download exe</a>
<a href="http://www.example.com/myprogram.zip" target="_self">click to download zip</a>
</body>

The issue is this: when I click on the first link (myprogram.exe), the browser (IE8 as well as FireFox) streams the myprogram.exe directly into the browser window: I see a whole lot of binary.

When I click on the second link (myprogram.zip), the browser asks me if I would like to open the file or save it to disk, which is what I expected to happen with the .exe.

This is the ONLY .exe download that causes this strange behaviour. I have downloaded .exes often and the browsers always ask me whether to open the file or save to disk.

Is there something that needs to be set on the web site itself, or the host or ... ?

+1  A: 

You need to set the Content-Disposition HTTP header.

UPDATE: The HTTP headers are typically controlled in the web server, e.g., Apache.

As another poster mentions, most browsers should download .exe files as an attachment automatically if the server is sending the correct Content-Type header. How to do this varies from server to server. Here's an article on setting MIME types (another name for content-type) in IIS. In Apache, it is typically done by editing the file your TypesConfig directive points to.

Hank Gay
Thanks for the swift answer. I'm sorry to be dim, but how do I do that in my HTML page?
Peter
You have to configure your webserver to send out the correct headers associated with the `.exe`-extension. How to do this, depends on your webserver.
Stefan Gehrig
You shouldn't need to set the content-disposition header, browsers should Do The Right Thing for executables if the correct content-type is set.
David Dorward
I agree, David. Of all file types that should NOT be opened in a browser window, I should imagine that .exe would come pretty close to the top of the list. Why are they happy to treat .zip in the expected manner, but not .exe. Maybe there's a good answer out there? ...
Peter
Hi Peter. Have you checked the headers that your server is sending? You can probably see these by using `curl -i $uri_for_your_exe` If it's not sending the proper `Content-Type` and/or `Content-Disposition` headers, you need to do some server configuration.
Hank Gay
Thanks, Hank. It's a bit of a long story, but I'm not the web site author, it's a colleague of mine who is doing that, and I'm just trying to help him trouble shoot this one issue. I'll pass on your advice, though. Thanks.
Peter
A: 

See this

How To Raise a "File Download" Dialog Box for a Known MIME Type

When you serve a document from a Web server, you might want to immediately prompt the user to save the file directly to the user's disk, without opening it in the browser. However, for known MIME (Multipurpose Internet Mail Extensions) types such as Microsoft Word ("application/ms-word"), the default behavior is to open the document in Internet Explorer.

You can use the content-disposition header to override this default behavior. Its format is:

Content-disposition: attachment; filename=fname.ext

rahul
+2  A: 

You need to correct the content-type your webserver is sending. It sounds like it is claiming that the data is text/plain. My mime.types file suggests exe files should be application/x-msdos-program

If you are using Apache, see http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addtype (or the similar page in the manual for the version you are using).

David Dorward
A: 

In the end it required AddType application/x-octet-stream exe being applied.

Thanks to all the answerers who pointed me that way.

Peter