Topic on Project:Support desk

Some Files Not Typed Properly

3
Lbillett (talkcontribs)

I have an xls file to upload.

  • $wgFileExtensions includes an entry for xls.
  • phpinfo() output says PHP Fileinfo extension is loaded.
  • $wgLoadFileinfoExtension = true;

In my environment, manually checking type with Fileinfo yields: application/vnd.ms-excell However, when attempting to upload this same file MW 1.23.2 it yields: File extension ".xls" does not match the detected MIME type of the file (application/zip).

It's as though something else is being used for MIME type detection on files. Any idea what might cause this? (and how to fix it?). Thanks!

88.130.86.46 (talkcontribs)

Hi!

Manual:$wgFileExtensions has more info on file uploads. However, I think your problem is not related to the file type, but to the MIME type. The MIME type "application/vnd.ms-excell" according to Manual:$wgMimeTypeBlacklist should no longer be blacklistet in your MediaWiki version. However, MediaWiki by default uses the mapping provided in includes/mime.types; this is configurable with Manual:$wgMimeTypeFile. Maybe this detects your file somehow incorrectly?

Lbillett (talkcontribs)

Ah, interesting. I tried setting $wgMimeTypeFile = "/etc/mime.types"; and attempted to upload the file again, but with the same result (I sooo hoped that was the answer!). It's mime type is being detected as application/zip, when should (I think) be application/vnd.ms-excel. Setting $wgMimeTypeFile = null; allows the upload, but still types it incorrectly. If you try to move it, it "doesn't match it's type".

What I really don't get is how fileinfo types it correctly, but somewhere mediawiki (which I've specificaly set (supposedly) to use fileinfo) does not. It looks like maybe MimeMagic.php could be doing it, after somehow failing to type it from the file's header data.

I tried disabling type detection altogehter with $wgVerifyMimeType = false; (there's low security risk in my environment), which allows uploading of files, but blows up when you try to move them. Seems the setting applies at upload, but not during a file move.

Might there be a way to set MIME type based on the file extension only? It would save a lot of these headaches, and be of little risk in our particular installation.

Reply to "Some Files Not Typed Properly"