<p>I've come across a rather interesing (and frustrating) problem with IE6. We are serving up some server generated pdfs and then simply setting headers in PHP to force a browser download of the file. Works fine and all, except in IE6 but <strong>only</strong> if the windows user account is set to standard user (ie. not administrator).</p>

<p>Since this is for a corporate environment, of course all their accounts are setup this way. Weird thing is, that in the download dialog, the Content-Type is not recognized:</p>

<pre><code>header( 'Pragma: public' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, pre-check=0, post-check=0' );
header( 'Cache-Control: public' );
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/pdf' );
header( 'Content-Disposition: attachment; filename="xxx.pdf"' );
header( 'Content-Transfer-Encoding: binary' );
echo $content;
exit;
</code></pre>

<p>I also tried writing the file content to a temporary file first so I could also set the <code>Content-Length</code> in the header but that didn't help.</p>

[{'answer_id': 49306, 'author': 'Stu Thompson', 'author_id': 2961, 'author_profile': 'https://Stackoverflow.com/users/2961', 'pm_score': 1, 'selected': False, 'text': '<p>I have had the exact same problem about a year ago, and after much googling and research, my headers (from Java code) look for IE6 &amp; PDFs like this:</p>\n\n<pre><code>    response.setHeader("Content-Type", "application/pdf "; name=" + file.getName());\n    response.setContentType("application/pdf");\n    response.setHeader("Last-Modified", getHeaderDate(file.getFile());\n    response.setHeader("Content-Length", file.getLength());\n</code></pre>\n\n<p>Drop everything else.  </p>\n\n<p>There is apparently something a bit whacky with IE6, caching, forced downloading and plug-ins.  I hope this works for you...a small difference for me is that the request initially comes from a Flash swf file.  But that should not matter.</p>\n'}, {'answer_id': 49325, 'author': 'pilif', 'author_id': 5083, 'author_profile': 'https://Stackoverflow.com/users/5083', 'pm_score': 2, 'selected': False, 'text': '<p>some versions of IE seem to take</p>\n\n<pre><code>header( \'Expires: 0\' );\nheader( \'Cache-Control: must-revalidate, pre-check=0, post-check=0\' );\n</code></pre>\n\n<p>way too seriously and remove the downloaded content before it\'s passed to the plugin to display it. </p>\n\n<p>Remove these two and you should be fine.</p>\n\n<p>And make sure you are not using any server-side GZIP compression when working with PDFs because some versions of Acrobat seem to struggle with this.</p>\n\n<p>I know I\'m vague here, but above tips are based on real-world experience I got using a web application serving dynamically built PDFs containing barcodes. I don\'t know what versions are affected, I only know that using the two "tricks" above made the support calls go away :p</p>\n'}, {'answer_id': 72399, 'author': 'Twan', 'author_id': 6702, 'author_profile': 'https://Stackoverflow.com/users/6702', 'pm_score': 0, 'selected': False, 'text': '<p>As pilif already mentions, make sure to turn off the server-side gzip compression. For me this has caused problems with PDF files (among other types) and for maybe-not-so-obscure reasons also with .zip files both under Internet Explorer and FireFox.</p>\n\n<p>As far as I could tell, the last bit of the zip footer would get stripped (at least by FireFox) causing a corrupted format.</p>\n\n<p>In PHP you can use the following code:</p>\n\n<pre><code>ini_set("zlib.output_compression",0);\n</code></pre>\n'}, {'answer_id': 134693, 'author': 'Tom De Leu', 'author_id': 22263, 'author_profile': 'https://Stackoverflow.com/users/22263', 'pm_score': 0, 'selected': False, 'text': '<p>The following bit of Java code works for me (tested on Firefox 2 and 3, IE 6 and 7):</p>\n\n<pre><code>response.setHeader("Content-Disposition", "attachment; filename=\\"" + file.getName() + "\\"");\nresponse.setContentType(getServletContext().getMimeType(file.getName()));\nresponse.setContentLength(file.length());\n</code></pre>\n\n<p>No other headers were necessary at all.\nAlso, I tested this code both with gzip compression on and off (using a separate servlet filter that does the compression). Doesn\'t make any difference (works without any problem in the four browsers I tested it on).\nPlus, this works for other filetypes as well.</p>\n'}, {'answer_id': 134719, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 0, 'selected': False, 'text': '<p>You can add an additional parameter that the server won\'t read to the url it might help too.</p>\n\n<p><a href="http://www.mycom.com/services/pdf?action=blahblah&amp;filename=pdf0001.pdf" rel="nofollow noreferrer">http://www.mycom.com/services/pdf?action=blahblah&amp;filename=pdf0001.pdf</a> </p>\n\n<p>I have run into cases where ie will be more likely to read the filename on the end of the url than any of the headers</p>\n'}, {'answer_id': 731183, 'author': 'Kornel', 'author_id': 27009, 'author_profile': 'https://Stackoverflow.com/users/27009', 'pm_score': 2, 'selected': False, 'text': "<h2>These headers are bogus!</h2>\n<pre><code>Content-Transfer-Encoding: binary\n</code></pre>\n<p>This header is copied from e-mail headers. It doesn't apply to HTTP simply because HTTP doesn't have any other mode of transfer than binary. Setting it makes as much sense as setting <code>X-Bits-Per-Byte: 8</code>.</p>\n<pre><code>Cache-control: pre-check=0, post-check=0\n</code></pre>\n<p>These non-standard values define when IE should check whether cached content is still fresh. <code>0</code> is the default, so setting it to <code>0</code> is waste of time. These directives apply only to cacheable content, and <code>Expires:0</code> and <code>must-revalidate</code> hint that you wanted to make it non-cacheable.</p>\n<pre><code>Content-Description: File Transfer\n</code></pre>\n<p>This is another e-mail copycat. <em>By design</em> this header <em>doesn't affect download in any way</em>. It's just informative free-form text. It's technically as useful as <code>X-Hi-Mom: I'm sending you a file!</code> header.</p>\n<pre><code>header( 'Cache-Control: must-revalidate, pre-check=0, post-check=0' );\nheader( 'Cache-Control: public' );\n</code></pre>\n<p>In PHP second line <em>completely overwrites</em> the first one. You seem to be stabbing in the dark.</p>\n<h2>What really makes a difference</h2>\n<pre><code>Content-Disposition: attachment\n</code></pre>\n<p>You don't have to insert filename there (you can use <code>mod_rewrite</code> or <code>index.php/fakefilename.doc</code> trick – it gives much better support for special characters and works in browsers that ignore the <em>optional</em> <code>Content-Disposition</code> header).</p>\n<p>In IE it makes difference whether file is in cache or not (&quot;Open&quot; doens't work for non-cacheable files), and whether user has plug-in that claims to support type of file that IE detects.</p>\n<p>To disable cache you only need <code>Cache-control:no-cache</code> (without 20 extra fake headers), and to make file cacheable you don't have to send anything.</p>\n<p><strong>NB: PHP has horrible misfeature called <code>session.cache_limiter</code> which hopelessly screws up HTTP headers unlesss you set it to <code>none</code>.</strong></p>\n<pre><code>ini_set('session.cache_limiter','none'); // tell PHP to stop screwing up HTTP\n</code></pre>\n"}, {'answer_id': 1196026, 'author': 'paulwhit', 'author_id': 7301, 'author_profile': 'https://Stackoverflow.com/users/7301', 'pm_score': 0, 'selected': False, 'text': '<p>I had a similar problem, but it might not be exactly related. My issue was that IE6 seems to have a problem with special characters (specifically slashes) in the file name. Removing these fixed the issue.</p>\n'}, {'answer_id': 2193047, 'author': 'A.J. Brown', 'author_id': 264016, 'author_profile': 'https://Stackoverflow.com/users/264016', 'pm_score': 0, 'selected': False, 'text': '<p><strong>If you are using SSL:</strong></p>\n\n<p>Make sure you do not include any cache control (or Pragma) headers.  There is a bug in IE6 which will prevent users from downloading files if cache control headers are used.  They will get an error message.</p>\n\n<p>I pulled my hair out over this for 2 days, so hopefully this message helps someone.</p>\n'}, {'answer_id': 3758994, 'author': 'Andreas Linden', 'author_id': 412395, 'author_profile': 'https://Stackoverflow.com/users/412395', 'pm_score': 0, 'selected': False, 'text': '<p>simply switch to this content type and it will work, also be sure Pragma ist set to something NOT equal "no-cache"</p>\n\n<pre><code>header( \'Content-type: application/octet-stream\'); # force download, no matter what mimetype\nheader( \'Content-Transfer-Encoding: binary\' ); # is always ok, also for plain text\n</code></pre>\n'}, {'answer_id': 5732601, 'author': 'vmaior', 'author_id': 717391, 'author_profile': 'https://Stackoverflow.com/users/717391', 'pm_score': 1, 'selected': False, 'text': '<p>I appreciate the time you guys spent on this post. I tried several combinations and finally got my symfony project to work. Here I post the solutions in case anyone will have the same problem:</p>\n\n<pre><code>public function download(sfResponse $response) {\n\n        $response-&gt;clearHttpHeaders();\n        $response-&gt;setHttpHeader(\'Pragma: public\', true);\n        $response-&gt;addCacheControlHttpHeader("Cache-control","private");        \n        $response-&gt;setContentType(\'application/octet-stream\', true);\n        $response-&gt;setHttpHeader(\'Content-Length\', filesize(sfConfig::get(\'sf_web_dir\') .       sfConfig::get(\'app_paths_docPdf\') . $this-&gt;getFilename()), true);\n        $response-&gt;setHttpHeader("Content-Disposition", "attachment; filename=\\"". $this-&gt;getFilename() ."\\"");\n        $response-&gt;setHttpHeader(\'Content-Transfer-Encoding\', \'binary\', true);\n        $response-&gt;setHttpHeader("Content-Description","File Transfer");\n        $response-&gt;sendHttpHeaders();\n        $response-&gt;setContent(readfile(sfConfig::get(\'sf_web_dir\') . sfConfig::get(\'app_paths_docPdf\') . $this-&gt;getFilename()));\n\n        return sfView::NONE;\n}\n</code></pre>\n\n<p>This works just fine for me in IE6,IE7, Chrome, Firefox.</p>\n\n<p>Hope this will help someone.</p>\n'}]
['https://Stackoverflow.com/questions/49284', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3196/']