Mime Types to guarantee download

Posted on 2006-05-18
Medium Priority
Last Modified: 2012-06-27
Hello fellow experts.

I have been building a website that has several download options on the pages that visitors go to, unfortunately I can't show it to you, since it is an extranet. The downloads include several files (.doc, .pdf, .eml, .ppt) that should not be opened in the browser, but always downloaded.

Now I've set up the mime types for .pdf to:


But when I click the .pdf file's link, it still opens in the browser

What am I doing wrong, it seems as if it won't listen to my mime type at all..

Thanks in advance,

Question by:DreamMaster
  • 6
  • 4

Accepted Solution

AndyAelbrecht earned 500 total points
ID: 16715653
Some research suggests Internet Explorer will almost all the time second guess the MIME type of the file you are sending; this results in the broken experience you are getting.

The browser should always listen to the MIME type, especially if it's forced.

Anyway, a MIME type which is more likely to work, not only in MS browsers:


I hope this helps,

LVL 19

Author Comment

ID: 16715690
Hi Andy,

Thanks for the quick response. For FireFox this works. My browser will perfectly display the choice to download it or open it.

In Internet Explorer however, it simply opens it all the same.

Do you think there is any other way for me to fool Internet Explorer so this file will also be downloaded no matter what I throw at it...(might be a very large brick if it continues to be so friggin' stubborn ;))


Expert Comment

ID: 16715734
Hey DreamMaster,

If you are prepared to go all the way, we can use a script to get teh download started.
Since I don't know if you are running ASP or PHP, I'm not gonna go into that (yet ;)).

But, if you are running Apache, setting this in your .htaccess file (in the dir your file is in) or, alternatively, in your httpd.conf:

<Files *.mp3>
ForceType application/octet-stream
Header set Content-Disposition attachment

should force your browser to download the file. This is pretty guaranteed to work except with IE 4.01 and IE 5.5 (<SP2), both of which have a bug which prevents this from working like it should.

Hope this helps,

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 19

Author Comment

ID: 16715769
I'm actually running ASP.NET on IIS,

But the fact of the matter is, (I just found out) FireFox will always download a .pdf.

I know that there are ways to get downloads to always show the dialog using extensive scripts behind it. That would however require me to change every single link on the site (and there are a whole lot of those)

There has got to be a way to fool the browser into thinking it doesn't know the filetype...

LVL 25

Assisted Solution

Rouchie earned 500 total points
ID: 16715917
Here is one I use for ASP....

' get the file to download
DIM fileToDownload
fileToDownload = Request.QueryString("file")

' start the loading procedure...
Const adTypeBinary = 1
Dim strFilePath

' Set filestream for appropriate file type
FileType = lcase(Right(fileToDownload, 4))
    Select Case FileType
        Case ".asf"
            Response.ContentType = "video/x-ms-asf"
        Case ".avi"
            Response.ContentType = "video/avi"
        Case ".doc"
            Response.ContentType = "application/msword"
        Case ".zip"
            Response.ContentType = "application/zip"
        Case ".xls"
            Response.ContentType = "application/vnd.ms-excel"
        Case ".gif"
            Response.ContentType = "image/gif"
        Case ".jpg", "jpeg"
            Response.ContentType = "image/jpeg"
        Case ".wav"
            Response.ContentType = "audio/wav"
        Case ".mp3"
            Response.ContentType = "audio/mpeg3"
        Case ".mpg", "mpeg"
            Response.ContentType = "video/mpeg"
        Case ".rtf"
            Response.ContentType = "application/rtf"
      Case ".htm", "html"
            Response.ContentType = "text/html"
      Case ".asp"
            Response.ContentType = "text/asp"
      Case ".pdf"
          Response.ContentType = "application/pdf"
      Case ".ppt"
          Response.ContentType = "application/mspowerpoint"
        Case Else
            'Handle All Other Files
            Response.ContentType = "application/octet-stream"
    End Select

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.LoadFromFile fileToDownload

Response.BinaryWrite objStream.Read

Set objStream = Nothing
Set FileType = Nothing
set fileToDownload = Nothing

LVL 19

Author Comment

ID: 16715967
Hi Rouchie,

Thanks for that. Right now I think I will have to ask the client how important it is to them to always show the dialog box when a link is clicked. We have, for example, provided them with an editor, that also includes the chance to create links themselves. It would mean we need to change the way that link is formed, but also make sure that the standard links to other pages remain normal links.

I really don't feel like having to do that, but what the client wants..the client gets...right? ;)

I'll keep you all informed..


Expert Comment

ID: 16716176
did you try application/octet-stream as MIME type DM ?
this is a generic MIME type, most browsers download this.

if you want to be able to control headers more specifically, scripting (see Rouchies script) or Apache is your only solutions.


LVL 19

Author Comment

ID: 16716200
I did...like you said, it second guesses my mime-type and opens it anyway.

I did find out that these mime types don't work on site level in IIS, but on Directory level (something I think is strange), but even that did not change anything..

I'll wait for the response from the client..and get back to you after that.

LVL 19

Author Comment

ID: 16732884
Hi there fellows,

As promissed I am back..I've been experimenting with this stuff all weekend and couldn't find a perfect solution anywhere.

The problem with the site I am building this for is that we hand the people an editor with which they can also create their own links, now I cannot make it for them in a way that it will detect a downloadable file and change the link to the downloadfile accordingly, so that's not an option. I could change all links automatically, but heck...that's not an option either as then they would not be able to create normal links anymore.

Mime-types, as Andy perfectly stated are almost always second-guessed by Internet Explorer which eliminates the idea I had to change the mime-types for the downloadable files so that they always would download.

Now seriously I'd say that the only real option I have is to tell them that every single document they want to provide for download should be zipped by default as that will always be downloaded, that or tell the users to use the right mouse button and select "Save as"..

Thanks for your help guys, I appreciate it!


Expert Comment

ID: 16732949
as a final remark, DreamMaster, you have your own editor; how hard would it be to add a checkbox (or something) while adding a link that says "this is a downloadable file" ? (example: [url=blah dl=1] for downloads, [url=blah] for non-downloads)

while you are parsing this (I suppose and hope that you are parsing when OUTputting, not while INputting (I mean I hope you save the unparsed text to your database and not your parsed text)), you could check for the dl=1 flag; if it's on, you do this:

<a href="download.asp?file=url">

(the download.asp script would be Rouchie's script here then)
if it's off, you do:

<a href="url">

this way, when the user edits his document afterwards and decides another file should be added, it wouldn't fubar your editor or links.

or, another way, you could pretty safely assume you want certain types of files downloaded anyway. (example: xls, ppt, pdf, doc)
you could just have the users edit their documents, add their links etc.
and while OUTputting, you could search your text for hrefs with this extension and replace the URL with download.asp?url

something like that should be doable, even in ASP; I can't really tell you how to for now as my ASP string function knowledge is kinda rusty, but if you know what I mean i'm sure you can come up with a working solution ?

if you want more info on this, feel free to ask it; if not, let's hope the client agrees to zip everything ;)

LVL 19

Author Comment

ID: 16732957
Sounds like something I could explore...

Thanks again Andy!


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question