Reputation: 1568
<a href="path/to/file/filename.xxx" download="filename.xxx">filename</a>'
When i click the link, my filename.xxx should be downloaded.
It works perfectly in chrome. But in Internet explorer, it opens the file instead of downloading. What could be the problem? Is there any properties that is to be added to make it work in ie.
And also i need a file download sample that works for all the browsers.
Upvotes: 23
Views: 106437
Reputation: 31919
It is known HTTP headers problem with Internet Explorer. Try to edit your server's .htaccess
file (if you use Apache) and include the following rules:
# IE: force download of .xxx files
AddType application/octect-stream .xxx
<Files *.xxx>
ForceType application/octet-stream
Header Set Content-Disposition attachment
</Files>
Upvotes: 0
Reputation: 6329
For apache2 server:
AddType application/octect-stream .ova
File location will depend on particular version of Apache2 -- ours is in /etc/apache2/mods-available/mime.conf
Reference:
https://askubuntu.com/questions/610645/how-to-configure-apache2-to-download-files-directly
Upvotes: 2
Reputation: 11
Zip your file (.zip) and IE will give the user the option to open or download the file.
Upvotes: 0
Reputation: 27627
The download attribute is not supported in IE (see http://caniuse.com/#search=download%20attribute).
That suggests the download attribute is only supported by firefox, chrome, opera and the latest version of blackberry's browser.
For other browsers you'll need to use more traditional methods to force download. That is server side code is necessary to set an appropriate Content-Type and Content-Disposition header to tell (or trick depending on your point of view) the browser to download the item. Headers should look like this:
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"filename.xxx\"
(thanks to antyrat for the copy and paste of the headers)
Upvotes: 20
Reputation: 3621
This is not a code issue. It is your default IE settings
To change the "always open" setting:
EDIT: If you ask me , instead of making any changes in the code i would add the following text "Internet Explorer users: To download file, "Rightclick" the link and hit "Save target as" to download the file."
EDIT 2: THIS solution will work perfectly for you. Its a solution i just copied from the other answer. Im not trying to pass it off as my own
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"filename.xxx\"
However you must make sure that you specify the type of file(s) you allow. You have mentioned in your post that you want this for any type of file. This will be an issue.
For ex. If your site has images and if the end user clicks these images then they will be downloaded on his computer instead of opening in a new page. Got the point. So you need to specify the file extensions.
Upvotes: 0
Reputation: 1516
You could configure this in your http-Header
httpResponse.setHeader("Content-Type", "application/force-download");
httpResponse.setHeader("Content-Disposition",
"attachment;filename="
+ "MyFile.pdf");
Upvotes: -3
Reputation: 16037
This must be a matter of http headers.
see here: HTTP Headers for File Downloads
The server should tell your browser to download the file by sending
Content-Type: application/octet-stream;
Content-Disposition: attachment;
in the headers
Upvotes: 0
Reputation: 27765
It should be fixed on server side. Your server should return this headers for this file types:
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"filename.xxx\"
Upvotes: 11