keatch
keatch

Reputation: 2207

Forcing IE7+ to download an XML file, using Apache2

little question that is going to take me mad!

I've an xml file that I want to download from a browser. I've set the correct mime type and attachment via Apache2 .htaccess

xpt is a file that has the first line as a regular xml file

 <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 

My .htaccess looks like this

    AddType application/octet-stream .xpt
   <FilesMatch "\.(?i:xpt)$">
       ForceType application/octet-stream
       Header set Content-Disposition attachment
   </FilesMatch>

Looking via Explorer Developer Tools (F12), the header in the Networks tabs looks correct. Every other browser has no problem, IE7+ yes.

Is there a solution, without resort to a wrapper?
Is there anything that I've missed in my configuration?

TIA

Upvotes: 1

Views: 2070

Answers (2)

keatch
keatch

Reputation: 2207

I've managed to find the solution, in this obscure thread from the drupal community: http://drupal.org/node/244852#comment-979530

My solution works as this:

AddType application/octet-stream .xpt

<FilesMatch "\.(?i:xpt)$">
  ForceType application/force-download
  Header set Content-Disposition attachment
  Header set Content-Description File-Transfer
  Header set Cache-Control "store, no-cache, must-revalidate"
</FilesMatch>

Still not understanding why IE7 has a behaviour so different from other browser. It ignore also the application/octet-stream when received as an header.

Upvotes: 2

daalbert
daalbert

Reputation: 1475

It looks like you are an the right track, but do your XML files have the .xpt extension? Also check the MIME.

AddType text/xml .xml
<FilesMatch "\.(?i:xml)$">
    ForceType text/xml
    Header set Content-Disposition attachment
</FilesMatch>

Upvotes: 1

Related Questions