imce over-riding headers set by upload.module in core when downloading excel files
| Project: | IMCE |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Our set up uses the private file download option, and we have a lot of excel calculator type tools for staff.
After upgrading to D6 from D5, excel files on our system were being re-named with a 'doc' suffix and would not display or save . The hack found at http://drupal.org/node/440572 was a reasonable temporary work around. But with the latest upgrade to 6.14, the hack didn't seem to work it's usual magic.
I disabled imce, and the problem went away.
After copious drupal_set_message tests (there is probably an easier way, but I ain't no coder!) I found 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.
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 for a temporary fix, 'cause I'm not sure of the implications ...
While searching came across finfo_file() needs the canonical path to the file, don't know if it's relevant.
Thanks for a great module.
Cliona

#1
Please try this patch that uses the new file_get_mimetype function of drupal.
#2
I'm getting a conflict between IMCE and file upload where video files are downloading with mime type of image/vnd.wap.wbmp. If I disable IMCE they get the correct video/quicktime mime type. Currently using IMCE 6.x-1.3, Drupal 6.14
#3
I found it was the first option using getimagesize that was causing the issue for me. I reordered the option to extract filemime from the db to be first and that resolved the issue for me.
diff -u imce.module_6.x-1.3 imce.module
--- imce.module_6.x-1.3 2009-11-30 10:28:12.000000000 +1000
+++ imce.module 2009-11-30 10:39:33.000000000 +1000
@@ -85,16 +85,16 @@
*/
function imce_file_download($file) {
if ($path = file_create_path($file)) {
- if ($info = @getimagesize($path)) {
+ if ($result = db_result(db_query("SELECT filemime FROM {files} WHERE filepath = '%s'", $path))) {
+ $type = $result;
+ }
+ else if ($info = @getimagesize($path)) {
$type = $info['mime'];
}
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;
- }
else if (function_exists('mime_content_type')) {
$type = mime_content_type($path);
}
I'm not sure why all the other options are there. I would have expected that the database would always contain the correct filemime, created when the file is uploaded.
#4
DB query is the last attempt concerning the cost of db hit and performance.
Since the other methods seem to be problematic we should just put the performance issues aside and query the db first as you suggest.
Here is the patch that also use the file_get_mimetype() of drupal core.
Please test and report back.
#5
I installed this patch and it works for me. Thanks.