Loading...
 
Skip to main content

.docx files uploaded as .zip files...

Status
Closed
Subject
.docx files uploaded as .zip files...
Version
9.x
Category
  • Usability
Feature
File Gallery (elFinder or standard UI)
Resolution status
Fixed or Solved
Submitted by
Jonas Jermann
Lastmod by
Jonas Jermann
Rating
(0)
Description

Docx files are uploaded as zip files

When I upload .docx files to my Tiki-Wiki server (using the Cyberduck WebDAV client on Windows 7) they are uploaded with the mime-type application/zip instead of application/vnd.openxmlformats-officedocument.wordprocessingml.document (the correct one). Consequently the browser cannot directly open them which is very annoying.

Some attempts to debug the problem

When I try to access a file on the web server directly by manually putting it in the homepage folder and downloading it directly from the web server the file is recognized correctly. For me this means that the mime-type of the Apache server is working properly.

I checked the same issue with a the same configuration and a fresh installation at my home pc: It also didn't work. In both cases I was using the 9.x SVN branch.

Strange enough it did work when I tried to upload to demo.tiki.org, (for both, 8x and 9x). However the mime-type was set to application/ms-word which is strictly speaking also not correct (but at least it then opens correctly). I have no idea why it works there... (?)

My overall guess is that it has something to do with the fact that .docx files are actually zip files. Maybe somewhere a content based mime-detection is performed (be it in the WebDAV client, the Apache server or on the Wiki) but instead an extension based detection should have been used to distinguish .docx files from .zip files. It might also have something to do with the deflate mod (not sure).

In any case/whatever the reason the proposed solution below seems to fix all my issues and probably also some other people's issues.

Files
  1. Filegallib
Solution

One possible solution/workaround

The following changes fix the issue for me:

1. Enhance the mime-type fix functionality

By applying the patch/change below the mime-type fix which was originally only for mime-types application/octet-stream (it was intended for images?) is extended to all mime-types and set according to the file extension in lib/mime/mimetypes.php (if the extension exists):

Copy to clipboard
Index: filegallib.php =================================================================== --- filegallib.php (revision 42490) +++ filegallib.php (working copy) @@ -3612,39 +3612,17 @@ function fixMime($fileData) { global $prefs; + global $mimetypes; include ('lib/mime/mimetypes.php'); if ($prefs['fgal_fix_mime_type'] != 'y') { return $fileData['filetype']; } - if ($fileData['filetype'] != "application/octet-stream") { + $suffix=strtolower(preg_replace('/.*\./', '', $fileData['filename'])); + $filetype = $mimetypes[$suffix]; + if ($filetype) { + return $filetype; + } else { return $fileData['filetype']; } - $suffix=strtolower(preg_replace('/.*\./', '', $fileData['filename'])); - switch($suffix) { - case 'jpg' : - case 'jpeg' : $filetype = 'image/jpeg'; - break; - case 'gif' : $filetype = 'image/gif'; - break; - case 'png' : $filetype = 'image/png'; - break; - case 'tif' : - case 'tiff' : $filetype = 'image/tiff'; - break; - case 'svg' : $filetype = 'image/svg+xml'; - break; - case 'pdf' : $filetype = 'application/pdf'; - break; - case 'doc' : $filetype = 'application/msword'; - break; - case 'ppt' : $filetype = 'application/vnd.ms-powerpoint'; - break; - case 'xls' : $filetype = 'application/vnd.ms-excel'; - break; - case 'docx' : $filetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; - break; - default : $filetype = 'application/octet-stream'; - } - return $filetype; } }


Note that the code is also available as an attachment...

In my case this means that the mime-type of the .docx file (which was application/zip originally) is changed accordingly based on the .docx extension (by checking the entry in lib/mime/mimetypes.php).

2. Update the mime-types in Tiki-Wiki

Unfortunately lib/mime/mimetypes.php does not contain the .docx/etc mime-types. So I replaced it with a more recent version (this could be done by using the script in mimetypes.php on a recent mime.types file which has all necessary extensions,

Alternatively one could simply add the following types (that's what I did):

Copy to clipboard
"docm" => "application/vnd.ms-word.document.macroEnabled.12", "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "dotx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "potm" => "application/vnd.ms-powerpoint.template.macroEnabled.12", "potx" => "application/vnd.openxmlformats-officedocument.presentationml.template", "ppam" => "application/vnd.ms-powerpoint.addin.macroEnabled.12", "ppsm" => "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", "ppsx" => "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "pptm" => "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", "xlam" => "application/vnd.ms-excel.addin.macroEnabled.12", "xlsb" => "application/vnd.ms-excel.sheet.binary.macroEnabled.12", "xlsm" => "application/vnd.ms-excel.sheet.macroEnabled.12", "xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xltm" => "application/vnd.ms-excel.template.macroEnabled.12", "xltx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.template",


3. Optionally

Also update lib/mime/mimeextensions.php and icons accordingly...

Conclusion

With this changes everything seems to work fine for me but I don't know enough about the Tiki Wiki and PHP to know whether this breaks something or if it is bad for some other reason.

In any case I would really appreciate if someone could at least take a look at the issue / proposed solution...

Importance
9 high
Easy to solve?
9
Priority
81
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
4268
Created
Thursday 26 July, 2012 14:55:45 UTC
by Jonas Jermann
LastModif
Saturday 06 July, 2024 10:21:44 UTC


Show PHP error messages