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.
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.
The following changes fix the issue for me:
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):
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).
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):
"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",
Also update lib/mime/mimeextensions.php and icons accordingly...
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...
To help developers solve the bug, we kindly request that you demonstrate your bug on a show2.tiki.org instance. To start, simply select a version and click on "Create show2.tiki.org instance". Once the instance is ready (in a minute or two), as indicated in the status window below, you can then access that instance, login (the initial admin username/password is "admin") and configure the Tiki to demonstrate your bug. Priority will be given to bugs that have been demonstrated on show2.tiki.org.
To help developers solve the bug, we kindly request that you demonstrate your bug on a show.tikiwiki.org instance. To start, simply select a version and click on "Create show.tikiwiki.org instance". Once the instance is ready (in a minute or two), as indicated in the status window below, you can then access that instance, login (the initial admin username/password is "admin") and configure the Tiki to demonstrate your bug. Priority will be given to bugs that have been demonstrated on show.tikiwiki.org.