I'm not sure if this is a problem with Drupal core, upload.module, or IE 6...

I have a site where I am keeping organizational/membership documents in a private file system under Drupal. These attached documents should never be accessible via http.

With Firefox, when I click on an attached PDF stored in a node as: example.com/system/files/my+file+name.pdf, it asks whether I want to open it in Acrobat Reader, save it, or I can choose another application. I can click OK, which launches Reader and I can read the file. Though this behavior is different than under an http-accessible file path, which opens the file within the scope of the browser itself, it works just fine.

With IE 6, when users click on the same attached PDF file, they get an option to Open or Save the document. If they attempt to open, Acrobat Reader starts up but then chokes stating: "There was an error opening this document. This file cannot be found." It appears the file downloads (subjective guess, based on the amount of time it takes before the error comes up). Also, there is no reference to a path or file name in the error message to troubleshoot further.

This has been tested on more than one machine, so it doesn't seem to be an issue with an isolated PC.

To reproduce:

  1. Make your attached files "private" rather than public/http-accessible in Drupal
  2. Create a node and upload a PDF or DOC attachment with core upload.module
  3. While viewing the node, click on the attached document to bring up an open dialog box
  4. Click on Open (if in IE it will fail, if in Firefox it will work as expected)

Side Note 1: It is possible to Save the file to disk and open it from the OS, but not possible to open it by clicking on the Open button.

Side Note 2: The file type PDF, DOC, XLS, etc., does not matter, but we want to use one that will force an application to load based on associated file-type. All file types fail in their native applications when the user clicks the Open button.

Without turning this into a well-deserved IE s*cks thread, does anyone have an idea of what may be going on here, or more importantly how to fix it? These folks are computer n00bs and all use IE. I have no control over their browser choice.

Thanks in advance for looking into this...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drubeedoo’s picture

Status: Active » Closed (duplicate)

I didn't see this earlier in my search, but this issue is a duplicate of:

http://drupal.org/node/30525

Darren Oh’s picture

Version: 4.7.0 » x.y.z
Status: Closed (duplicate) » Active

This issue points out a serious bug that affects all browsers. Both Drupal 4.7 and Drupal 5.0 have this problem: when files are public, they open in the browser, and when files are private, they download. I cannot think of any good reason to keep this behavior.

tkgafs’s picture

With some very limited testing, it would appear that the files open correctly if using IE7 it seems to be only IE6 which is affected by the problem, but for me at least it is a very big problem as most users seem unable to grasp they can simply download the file then open it locally.

I keep getting messages I cant open the file its corrupted

if you want a test try http://www.dibbletree.com/node/88 and try any of the pdfs on the page if you use firefox 1.5 or 2 or IE7 they open ok if you use IE6 you must download the file before opening it

Tkgafs

webchick’s picture

Can you guys please try this on a *completely clean* 4.7 install from latest 4.7 CVS that (aside from the default stuff that happens when you install Drupal) has only uid 1 created, the upload module enabled, and private file setting switched on?

I was not able to reproduce it this way, although I can reproduce it on one of our sites with a bunch of contrib and some custom modules.

webchick’s picture

Btw, here is a function I placed in our custom module that seemed to get rid of this error:

/**
 * Implementation of hook_file_download().
 *
 * For PDF and XLS files, returns custom headers so that IE
 * can open the files without an error.
 */
function custom_file_download($file) {
  $dir = variable_get('file_directory_path', 'files');
  $ext = substr(strrchr($file, "."), 1);
  if ($ext == 'pdf' || $ext == 'xls') {
    return array(
      'Cache-Control: must-revalidate, post-check=0, pre-check=0',
      'Content-Type: application/octet-stream',
      'Content-Length: ' . filesize($dir .'/'. $file),
      'Content-Disposition: attachment; filename="'.$file.'"',
    );
  }
}
Darren Oh’s picture

This issue affects Safari, Firefox, and Internet Explorer on my Mac. I did as webchick requested (see report in issue 30525 for system information) using a fresh install of Drupal 4.7 from CVS with no contrib modules, only one user, the upload module enabled, and files set to private.

The only browser on my Mac that will open a PDF attachment on my clean Drupal site is RealPlayer.

tkgafs’s picture

Webchick,

in my case the upload module is not enabled, I am using private files with the attachment & filemanager modules but getting exactly this error, but for me it works ok on firefox and IE7 but not IE6.

Background to my particular case

I have only ever used 4.7 and everything was running fine until my hosting company managed to erase my home directory containing all the drupal code, but my database was left intact.

I re downloaded 4.7 and all the modules I use from the drupal site and pretty quickly had the site up and running again.

But one thing I hadn't understood was that a module you install as a 4.7 module might be different a few weeks later when you re-install it !! although its still called module xyz ver 4.7.0

since the reinstall of my code base this is the one thing that is not working as it was before and I'm a bit at a loss as to where the problem lies

hope this helps to track down problem area

tkgafs

tkgafs’s picture

Sorry meant to add in my case download urls look like www.example.com/filemanager/active?fid=xx where xx is the file number

tkgafs

Darren Oh’s picture

I tracked down the problem to the Content-Disposition header that Drupal adds to any file with a type other than text/ or image/. PDF files are type application/pdf. In Drupal 4.7, the offending lines are 194 and 198 in upload.module.

Information on the Content-Disposition header is available here: http://www.ietf.org/rfc/rfc1806.txt. Browsers that do not understand this header will ignore it. That means that if IE7 and some versions of FireFox are opening private files in a browser window, it's actually a bug. In my experience, both FireFox 1.5 and FireFox 2.0 download rather than open files with this header.

You can see the difference in the headers sent when files are private here (using two Drupal Web sites I maintain):

Public setting: http://web-sniffer.net/?url=http%3A%2F%2Ftest.sidepotsinternational.com%...

Private setting: http://web-sniffer.net/?url=http%3A%2F%2Fbass.sidepotsinternational.com%...

tkgafs’s picture

thanks for that info in the filemanager module at approx line 580 is the following code

 $default_headers = array(
    'Content-Type: '. $file->mimetype,
    'Content-Length: '. $file->size,
    'Content-Disposition: attachment; filename="'. $file->filename .'"'
  );

If I remove the Content-Disposition line the pdf now opens inline in the browser window in both IE6 and firefox 1.5 I dont have any other browsers to test nearby.

This is what I actually want to happen and I'm happy to remove it from the code but it doesnt really answer the question as to why IE6 actually fails to correctly download and then pass on to acrobat the pdf file

as you say and I'd actually forgotten firefox used to open the file inline but with the content-disposition header it actually asks you what you want to do with the file, which is presumably the correct behaviour

thanks to you all for your help

does this also need to be raised as an issue with the filemanager module ?

Tkgafs

Darren Oh’s picture

Yes, please open an issue with the filemanager module. This issue concerns the upload module. The problem with IE6 was fixed for upload module. See issue 30525 for details.

Darren Oh’s picture

Status: Active » Needs review
FileSize
638 bytes

This patch adds application/pdf to the mime types that should be viewed inline.

webchick’s picture

Version: x.y.z » 5.x-dev

Hm. I wonder if that is a proper fix though. IIRC we were also having this problem with .xls, .doc files, etc.

Darren Oh’s picture

There's really no need to send the Content-Disposition header at all. It just makes private and public files display differently, which confuses people. The proper way to handle mime types is to let users configure their own browsers the way they want to.

There was probably a security rationale for including the header, but if uploads are handled properly, we shouldn't have to worry about malicious downloads. So I deprecate my patch and ask that the Content-Disposition header be removed.

Darren Oh’s picture

FileSize
701 bytes

For good measure, here is a patch to remove the header and return control of how files are displayed to viewers.

Darren Oh’s picture

For those who are nervous about this patch:

Content-Disposition is an optional header; in its absence, the MUA may use whatever presentation method it deems suitable.
From page 2 of http://www.ietf.org/rfc/rfc1806.txt

RobRoy’s picture

Title: attachments in system/files fail to open » Private files show open/save prompt for PDFs, etc. while public files automatically open inline

So this issue needs a title change as this isn't about files failing to open in IE 6 as http://drupal.org/node/30525 fixed that. The issue at hand is how private files show an open/save prompt for PDFs, XLS, etc. and public files just open them inline.

+1 on this patch as it returns the control to the browser and works as expected in making public/private files download in a consistent manner.

tkgafs’s picture

patch works for me

Darren Oh’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the reviews.

RobRoy’s picture

Status: Reviewed & tested by the community » Needs review

Usually you wait for someone else to RTBC your patch. :P

I think this needs another look as I was checking it out in IE 6 and clicking on a private PDF with this patch would open the current browser window to a blank window in IE 6 with the url of http://example.com/system/files/whatever.pdf and then popup an Acrobat reader with the file. Anyone else experiencing that behavior?

Darren Oh’s picture

It sounds like a browser setting. How does it work when you set files to public?

AjK’s picture

Patch at #15 works and doesn't appear to introduce any side effects. I would have set this RTBC but RobRoy's comment at #20 needs looking into I guess.

In reply RobRoy's #20 comment, I don't get this effect. Just works fine.

regards,
--AjK

drumm’s picture

Committed to HEAD.

drumm’s picture

Status: Needs review » Fixed
Darren Oh’s picture

Version: 5.x-dev » 4.7.x-dev
Status: Fixed » Patch (to be ported)

This is needed in 4.7 as well.

Dries’s picture

This reverts patch http://drupal.org/node/30525, which was aimed to fix upload.module problems with IE. Are we sure this doesn't re-introduce problems on IE?

Darren Oh’s picture

That patch just added a comma to the end of the Content-Disposition line. The line was already there. Removing the line will not cause any problem.

Darren Oh’s picture

Version: 4.7.x-dev » 5.x-dev

Quoting drumm from issue 30525: "I checked the history before committing and a Content-disposition header has been there since the beginning of upload module."

Marked for porting to 4.7.

chx’s picture

Version: 5.x-dev » 4.7.x-dev
Status: Patch (to be ported) » Reviewed & tested by the community
FileSize
1.11 KB

OK, let's remove then. Someone entered a *TAB* into the Drupal source!! Oh horror. Removed.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied

Anonymous’s picture

Status: Fixed » Closed (fixed)
avorio’s picture

Version: 4.7.x-dev » 7.0
Component: upload.module » file system
Status: Closed (fixed) » Active

I'm finding this exact same problem on my installation of Drupal 7.0.

bfroehle’s picture

History

Upload Module

Looking through the history (via git log -Sdisposition), it's clear that the Content-Disposition header was removed from the upload module in this patch.

CCK FileField

In CCK FileField, the commit

commit a7da1cd39f893cdf629f9b9a2cd423f43b06c5d3
Author: Darrel O\'Pry <dopry@22202.no-reply.drupal.org>
Date:   Thu Feb 1 09:27:38 2007 +0000

    backporting some fixes, untested... use at your own risk!!

copied upload_file_download() (from a version before the upload module patch) into filefield_file_download().

The list of inline mime types was made configurable in #485336: Make Content-Disposition configurable for private downloads (using the variable 'filefield_inline_types').

When CCK FileField entered core (#391330: File Field for Core) this was preserved (the variable being renamed to 'file_inline_types'). The code was later split out to a separate function (file_get_content_headers) but the logic preserved in #943112: file_file_download should delegate header checks to a separate function.

Current Status

Currently the list of MIME types which should show up as inline is configurable via 'file_inline_types'. See #1001664: Replace file_inline_types variable with a field formatter setting for an issue which would make this configurable via the UI.

But perhaps we should discuss whether this is really needed at all.

bfroehle’s picture

Version: 7.0 » 7.x-dev
Status: Active » Needs review
FileSize
996 bytes

Patch attached for 7.x-dev. Now I have no idea if the state of the universe has changed such that content-disposition (while once deemed a bad idea) might now be the proper thing to do.

Status: Needs review » Needs work

The last submitted patch, 61528-remove-content-disposition.patch, failed testing.

bfroehle’s picture

For the curious, the one failing test in #34 is an assertion that the content disposition header was sent correctly. (Obviously it won't be if you don't actually send it).

The assertion was added in #898036: Private images broken, but there's no mention in the issue about why it was added.

quicksketch’s picture

This should be created as a new issue (task or feature request). There's no good reason for reopening an issue that was closed nearly 5 years ago.

chx’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs tests

Well, it's a clear regression and the exact same as this issue so reopen IMO is ok.

bfroehle’s picture

Version: 8.x-dev » 4.7.11
Component: file system » upload.module
Status: Needs work » Closed (fixed)
Issue tags: -Needs tests