Almost 2 months without any reaction to http://drupal.org/node/395428
Trying again, starting a new issue...

When downloading files:

1- jpg and pdf files are readily opened and keep their original name

2- pub (MS Publisher) files completely lose their extension.
The file name follows the same rules as bellow depending on the browser.

3- other files generally keep their extension, but are renamed.
The name seems to be arbitrarily chosen by the web browser.
For example for the same file originally named "s88-01.doc"
- Firefox rename it "H8jB6jTR.doc.part.doc"
- Chrome rename it "download (1).doc" (all files are named "download", with the number incrementing)
- IE rename it "controlchaingroup_fr.doc", from the name off the web site "controlchaingroup.fr"

In all browsers, the correct name appear when overflying the file link.

Comments

jvieille’s picture

REALLY NEED HELP!!!

This module would be really great, if it was working

jvieille’s picture

Project: Private Upload » Drupal core
Version: 6.x-1.0-rc2 » 6.10
Component: Code » upload.module

I found it!

This is a several versions old problem.... Looks like almost nobody need file access control!

It has been silently solved here:
http://drupal.org/node/180778#comment-318639
The patch is here:
http://drupal.org/files/issues/upload.module.d6.content-disposition_0.patch

I hacked my clean (now dirty) D6.10: just added this line
'Content-Disposition: filename="'. mime_header_encode($file->filename) .'"',
after the line 154 in upload.module

May we havve htis committed in Core please!

Stol’s picture

This is indeed an old issue. I use the filefield of CCK instead of of the upload module. At least in Drupal 5 the filefield module doesn't have this issue.

jvieille’s picture

The CCK filefield does everything but proper access control.
I need the simple and lean Core upload module working as I use Private Upload to control file access,, and this module is not compatible with Fielfield.

If it this module is not planned to be fixed, it shall be removed as this is a critical bug!

But the fix is so simple that it would be extremely interesting to know the valid reason why it could not be committed.
We get core updates on a regular basis that only seem to address security issues that would only be of importance exceptionnally compared to such really annoying bug.

ngaur’s picture

Title: Incorrect names when downloading files » Need to set Filename in Mime Headers when downloading files
Status: Active » Needs review

I'm setting this to status: needs review, as it looks likely that the patch you've located is to the point.

I'm also renaming this issue to more clearly describe the problem.

Anyone reviewing this should look at #180778: Implement Content-Disposition comments #15 and #16 for the appropriate patches, which are quick to understand and apply.

jvieille’s picture

What kind of review is still needed?
The fix was issued in 2007...
May be not many people protect their files, so not much dedication to solve the issue.

Whatever happens with the fix, it cannot be worse than the current situation where using private files simply does not work.

ngaur’s picture

Tell me if I'm wrong, but I figure that needs review means it's not a case of the bug needing to be found so much as the solution needs to be checked for correctness. I'm new to the drupal project's workflow though, and I'm quite ready to be corrected.

OK, so here's some review.

I've just taken a look at RFC 2183. The header format implemented in the patch is not RFC compliant.

1/ It needs the disposition-type to be specified. Looks like 'attachment' is the apropriate value So, the added line would now look something like:

+         'Content-Disposition: attachment; filename="'. mime_header_encode($file->filename) .'"',

A significant effect of this is that it forces a browser to download the file. eg a .pdf file will not be displayed in a window care of a user's Adobe acrobat plugin. That's probably a good thing.

2/ RFC 2183 stipulates that the filename MUST be encoded as specified in RFC 2184. However, It looks like Drupal's mime_header_encode function documentation refers to RFC 2047. I'm not familiar with all of what has changed, but given the dates of the documents, I'd say that unicode would be the big one. RFC 2047 dates back to 1996 when unicode had little to no support in mail and web software. Unlike RFC 2047, The code of the drupal function refers to UTF-8, so there's a documentation bug at best. My reading of the encoding function says that it doesn't necessarily escape 'tspecials' (see RFC 2045), including characters like ',', ':', ' ', '=' and ';' which MIME uses to delimit fields in the header, and which would create problems if the header line were to wrap (valid MIME behaviour, but presumably uncommon in web browsers). One would hope that web browsers don't trust server headers enough for this to be exploitable.

At this moment, mime_header_encode does not provide a suitable encoding function for the proposed purpose. That should be fixed.

jvieille’s picture

That's a bit too technical for me...

I suggest that this new - certainly very valuable comment - should be taken into account as a separate issue.

the currrent patch solves the problem almost 100%, it does not seem to make Drupal core "worse" than it is currently.

This new input willl simpy mprove things.

The problem is that we are going to dig into another probelm that will postpone the fix for years again - the community is still waiting for 2 years for this imple line of code

ngaur’s picture

I'd agree with you in regards to my second point, but not in regards to my first point.

Corrected Patches attached. These are untested, but should be fine. Let me know how you go with them.

The fix to the mime header encoding should be treated as a separate issue. I've been meaning to file a bug report, but haven't had much time.

jvieille’s picture

That OK for me.
Works at best.

ngaur’s picture

Status: Needs review » Reviewed & tested by the community

Can someone commit this please?

gábor hojtsy’s picture

Version: 6.10 » 7.x-dev

Drupal 7 goes first.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

ngaur’s picture

albertoperego’s picture

love you!! It works!!

ngaur’s picture

Status: Needs work » Needs review

albertoperego, could you clarify which drupal version you've tested this with?

Status: Needs review » Needs work

The last submitted patch failed testing.

ngaur’s picture

Title: Need to set Filename / File type in Mime Headers when downloading files » Need to set Filename in Mime Headers when downloading files
Version: 6.14 » 7.x-dev
Status: Needs review » Needs work
Issue tags: -private files, -download of private files error, -MIME headers
StatusFileSize
new432 bytes
new438 bytes
new444 bytes

Patch files were produced with file names relative to the wrong working directory, so the automated testing system complained.

These new versions of the patch files should hopefully keep it happy.

[Note - it seems I can edit the comment, but not mark the D6 patch as being incorrect. See #21 below]

antosanto’s picture

Version: 7.x-dev » 6.13

The correct line to add is:

'Content-Disposition: attachment; filename="'. mime_header_encode($file->filename) .'"'

instead of

'Content-Length: attachment; filename="'. mime_header_encode($file->filename) .'"'

This works for me on Drupal-6.13

Greetings.

cmorrish’s picture

Title: Need to set Filename in Mime Headers when downloading files » Need to set Filename / File type in Mime Headers when downloading files
Version: 6.13 » 6.14
Status: Needs work » Active
Issue tags: +private files, +download of private files error, +MIME headers

Our set up uses the private file download option.
After upgrading to D6 from D5, prior to putting in this hack, excel files on our system were being re-named with a 'doc' suffix and would not display or save . With the hack, while an excel file was displayed in the download dialog in IE6 as excel, and saved ok, in Firefox on the mac it was still displaying as a word document for download, and the headers indicated a Content type of 'application/msword'. With the latest upgrade to 6.14, the hack didn't seem to work it's usual magic.

I disabled the contributed module imce, and the problem went away.

Might the difficulty generally lie in contributed modules that use hook_file_download possibly over-riding the Content type set by the Upload module?

After copious drupal_set_message tests (there is probably an easier way, but I ain't no coder!) I found in my case it was the use of finfo_file at line 92 in imce.module that set the header Content type to "application/msword", which then overrode the original upload module type header of "application/vnd.ms-excel".

Below was my temporary solution for imce which may help as an illustration if there are other modules involved (will also post to the imce issues)

Swap the order of the 'finfo_file' test that is causing errors, with the db test that works ok.

Original (at line 91 in imce.module) -

     else if (function_exists('finfo_file') && $finfo = @finfo_open(FILEINFO_MIME)) {
       $type = finfo_file($finfo, $path);
       finfo_close($finfo);
     }
     else if ($result = db_result(db_query("SELECT filemime FROM {files} WHERE filepath = '%s'", $path))) {
       $type = $result;
      }

Change to -

    else if ($result = db_result(db_query("SELECT filemime FROM {files} WHERE filepath = '%s'", $path))) {
      $type = $result;
    }
    else if (function_exists('finfo_file') && $finfo = @finfo_open(FILEINFO_MIME)) {
      $type = finfo_file($finfo, $path);
      finfo_close($finfo);
    }

Used a swap rather than a comment out, as the least disruptive option. And it's good to have the option of viewing in the browser again.

Hope this is of some help, I've set it back to active (with the greatest trepidation) because I'm not sure this would resolve the original difficulty that @jvieille was having ... but I think the problem may not be in core.

Cliona

ngaur’s picture

Status: Active » Needs review
StatusFileSize
new443 bytes

Corrected D6 version of the patch attached. I believe the ones for D5 and D7 are correct.

Can people who use these successfully (or not) please say so on this page. It's a bit frustrating to have fixed the problem but have noone stepping in to commit it. Perhaps some feedback will help that process.

jvieille’s picture

Title: Need to set Filename in Mime Headers when downloading files » Need to set Filename / File type in Mime Headers when downloading files
Version: 7.x-dev » 6.14
Status: Needs work » Needs review
Issue tags: +private files, +download of private files error, +MIME headers

For me, it works since I discovered in April a patch form Feb 2008.
The latest patch is fine too.
Should have been committed a long time ago.. Still hacking Drupal core each time a new version is released...
Hope this helps

wims’s picture

Assigned: Unassigned » wims

Yes, worked for mee to.
Drupal 6.14

Thanks,

Wims

gruzik’s picture

I have similar problem, except that I don't use upload module (uploading files via FTP).

- Drupal 6.15
- private file system
- FCKEditor + IMCE as file browser

File names are totally messed up. Switching between private and public file access don't help.
What to do if I don't use the upload module?

Andrzej

dpearcefl’s picture

Assigned: wims » Unassigned
Priority: Critical » Normal
Status: Needs review » Postponed (maintainer needs more info)

Has this been fixed in the latest D6?

dpearcefl’s picture

Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Needs work

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.