Mime Types to guarantee download

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,

LVL 19
Who is Participating?
AndyAelbrechtConnect With a Mentor Commented:
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,

DreamMasterAuthor Commented:
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 ;))

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,

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

DreamMasterAuthor Commented:
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...

RouchieConnect With a Mentor Commented:
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

DreamMasterAuthor Commented:
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..

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.


DreamMasterAuthor Commented:
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.

DreamMasterAuthor Commented:
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!

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 ;)

DreamMasterAuthor Commented:
Sounds like something I could explore...

Thanks again Andy!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.