Loading...
 

.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.

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):

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):

"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 (Tiki 19+)
Please demonstrate your bug on show2.tiki.org
 About show2.tiki.org

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.

Version: Create show2.tiki.org instance
Ticket ID
4268
Created
Thursday 26 July, 2012 14:55:45 GMT-0000
by Jonas Jermann
LastModif
Tuesday 14 August, 2012 08:10:35 GMT-0000

Attachments

 filenamecreatedhitscommentversionfiletype 
filegallib.diff 31 Jul 12 21:26 GMT-000062mime-type fix patch


Keywords

The following is a list of keywords that should serve as hubs for navigation within the Tiki development and should correspond to documentation keywords.

Each feature in Tiki has a wiki page which regroups all the bugs, requests for enhancements, etc. It is somewhat a form of wiki-based project management. You can also express your interest in a feature by adding it to your profile. You can also try out the Dynamic filter.

Accessibility (WAI & 508)
Accounting
Administration
Ajax
Articles & Submissions
Backlinks
Banner
Batch
BigBlueButton audio/video/chat/screensharing
Blog
Bookmark
Browser Compatibility
Calendar
Category
Chat
Comment
Communication Center
Consistency
Contacts Address book
Contact us
Content template
Contribution
Cookie
Copyright
Credits
Custom Home (and Group Home Page)
Database MySQL - MyISAM
Database MySQL - InnoDB
Date and Time
Debugger Console
Diagram
Directory (of hyperlinks)
Documentation link from Tiki to doc.tiki.org (Help System)
Docs
DogFood
Draw -superseded by Diagram
Dynamic Content
Preferences
Dynamic Variable
External Authentication
FAQ
Featured links
Feeds (RSS)
File Gallery
Forum
Friendship Network (Community)
Gantt
Group
Groupmail
Help
History
Hotword
HTML Page
i18n (Multilingual, l10n, Babelfish)
Image Gallery
Import-Export
Install
Integrator
Interoperability
Inter-User Messages
InterTiki
jQuery
Kaltura video management
Karma
Live Support
Logs (system & action)
Lost edit protection
Mail-in
Map
Menu
Meta Tag
Missing features
Visual Mapping
Mobile
Mods
Modules
MultiTiki
MyTiki
Newsletter
Notepad
OS independence (Non-Linux, Windows/IIS, Mac, BSD)
Organic Groups (Self-managed Teams)
Packages
Payment
PDF
Performance Speed / Load / Compression / Cache
Permission
Poll
Profiles
Quiz
Rating
Realname
Report
Revision Approval
Scheduler
Score
Search engine optimization (SEO)
Search
Security
Semantic links
Share
Shopping Cart
Shoutbox
Site Identity
Slideshow
Smarty Template
Social Networking
Spam protection (Anti-bot CATPCHA)
Spellcheck
Spreadsheet
Staging and Approval
Stats
Survey
Syntax Highlighter (Codemirror)
Tablesorter
Tags
Task
Tell a Friend
Terms and Conditions
Theme
TikiTests
Federated Timesheets
Token Access
Toolbar (Quicktags)
Tours
Trackers
TRIM
User Administration
User Files
User Menu
Watch
Webmail and Groupmail
WebServices
Wiki History, page rename, etc
Wiki plugins extends basic syntax
Wiki syntax text area, parser, etc
Wiki structure (book and table of content)
Workspace and perspectives
WYSIWTSN
WYSIWYCA
WYSIWYG
XMLRPC
XMPP




Useful Tools

Show PHP error messages