Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I set the 'permitted upload file extensions' to: zip rar
I'm getting the following when uploading a zip file:
"The selected file template.zip could not be uploaded. The file contents (application/x-zip) do not match its extension (zip)."
Comment | File | Size | Author |
---|---|---|---|
#12 | mimedetect_444724.patch | 2.51 KB | drewish |
#12 | mimedetect_444724.D7.patch | 2.53 KB | drewish |
#9 | mimedetect_use_magic.patch | 1.98 KB | quicksketch |
#3 | template.zip | 3.21 KB | itaine |
Comments
Comment #1
quicksketchSounds like mimedetect isn't working properly to identify the file type. Have you set up the "file" command at admin/settings/mimedetect? It would probably help identify the problem if you could upload the file to drupal.org or if it's a large file, make it available for download elsewhere.
Comment #2
itaine CreditAttribution: itaine commentedthx for the quick response! Let me look into the mimedetect settings first and report back shortly.
when I go there I get the following
"The MimeDetect module is using PHP's fileinfo extension to detect MIME types. There are no settings for the extension. "
I unzipped the archive and rezipped it myself to make sure it actually a zip file. I will attach it though. Checked to make sure the php_fileinfo extension is active and it is. Mind you I'm of course testing on a wamp setup not sure if it requires to be on a UNIX server to work.
Comment #3
itaine CreditAttribution: itaine commentedComment #4
itaine CreditAttribution: itaine commentedok I've narrowed it down. Everything works as it should. It appears there is just a problem with the application/zip mime-type. I will update the title of this issue to reflect that.
Comment #5
itaine CreditAttribution: itaine commentedComment #6
drewish CreditAttribution: drewish commentedyeah i think the magic library we ship is kind of limited. i'm not sure how to write a signature for it for zip files. might be better to use the system's if available. there's an issue for making the mime file customizable.
Comment #7
itaine CreditAttribution: itaine commentedwhen you say the system's are you referring to the upload module?
Comment #8
billnbell CreditAttribution: billnbell commentedIt appears that fileinfo and file relies on a magic file. If this file is not current, this module will not work.
From the command line type "file filename" and it should something other than zip.
Comment #9
quicksketchThis patch does two things: 1) Updates our magic file so that it returns "application/zip" instead of "application/x-zip" so that it matches file_get_mimetype() and 2) Makes mimedetect actually use the magic file. Right now it looks like we're shipping mimedetect with a magic file, but not actually using it anywhere.
Comment #10
drewish CreditAttribution: drewish commentedDefinitely a bug but technically we are using it with the PHP mimedetech extension, just not the file command...
Comment #11
quicksketchAh, right I hadn't seen that reference. It'd definitely be handy to use the same magic file in both places.
Comment #12
drewish CreditAttribution: drewish commentedminor tweak. committed to HEAD, D6 and D5.
Comment #13
quicksketchWorks great, thanks drewish.
Comment #15
Weka CreditAttribution: Weka commentedI am experiencing the same issue with ODT and RTF files.
Let me know if I should open a separate issue for this.
The selected file test.odt could not be uploaded. The file contents (application/zip) do not match its extension (odt).
The selected file test.rtf could not be uploaded. The file contents (text/rtf) do not match its extension (rtf).
I tested this with files created in OpenOffice 3.1.0 and NeoOffice NeoOffice 3.0.1.
Running Drupal 6.15, FileField 6.x-3.2, MimeDetect 6.x-1.2.
Comment #16
boabjohn CreditAttribution: boabjohn commentedSorry guys, this should be clear from the discussions above, but I'm not sure what to do next (as possibly weka feels as well?)...
Right now (6.x-1.2) mimedetect's config interface says:
"The MimeDetect module is using PHP's fileinfo extension to detect MIME types. There are no settings for the extension."
I can get into a webmin interface and see some settings for the php.ini file, but nothing looks like a fileinfo.
I've posted my situation with kml files on filefield's queue at: http://drupal.org/node/775188
Where/how to edit what?
Comment #17
boabjohn CreditAttribution: boabjohn commentedHello. Quicksketch is back on the queue after drupalcon.SF and reckons the problem is my magic file (http://drupal.org/node/775188).
Looked in the mime.magic file and could not find a reference to kml or kmz files. Searched extensively and found a reference that seems to work.
Added this line under Local Stuff in modules/mimdetect/mime.magic:
CLARIFICATION: not trying to pollute this thread, but my issue seems to be the same, just with a different filetype.
And a further note: I'm not sure why this whole thing doesn't degrade nicely back to Apache. In my case the mimetype exists in the httpd.conf file. I don't suppose there's any way to use something like an automated drush command to suck the contents of the local MimeMagicFile into the local mimedetect/mime.magic file? Or, more practically, allowing users to point to a symbolic link to the Apache file, and asking MimeDetect to *also* parse it...?
Comment #18
boabjohn CreditAttribution: boabjohn commentedFWIW, my clever insertion above did allow me to upload KML files, but on the next run of update.php the PHP File Extension complained:
Fileinfo could not load the magic file. It could be corrupted. Try reinstalling the magic file distributed with the MimeDetect module.
Yep: sure would be nice to actually fix this properly. Anyone have an idea about the required syntax, or is it a more profound issue?
Comment #19
boabjohn CreditAttribution: boabjohn commentedecho repeat echo ... can I help answer the question: what is the recommended way to get kml files uploaded to a Drupal site that has chosen to also run this fine module?
thanks.
Comment #20
ravendawson CreditAttribution: ravendawson commentedAnother problem I encounter with using the mime application/zip to identify the ZIP file is that it only identifies the compressed file, not archive’s contents.
Comment #21
3dloco CreditAttribution: 3dloco commentedI am getting same error for rar and gzip files, to fix it I changed magic.mime file as follows:
to
and it now it works...
Thanks,
KH
Comment #22
janis_lv CreditAttribution: janis_lv commented#21, thanks, solved my issue too.
Comment #23
brpubs CreditAttribution: brpubs commentedI'm running into the same issue with a docx file -- I've got a site taking admission applications to a graduate program, and I'm getting the message "The selected file ... could not be uploaded. The file contents (application/zip) do not match its extension (docx)."
Doc files and pdfs both work in the form (which is a custom module) without problems. Docx files worked several months ago, before I installed mimedetect, which I added to enable listhandler and mailhandler to import attached files. Docx files do work with some other parts of the site, like webforms or just attaching files to a page. The only difference I can figure out is that with the admission application, the file upload is a cck field and uses filefield, which in turn is callling mimedetect.
Fixing this is a little over my programming head. Any advice on how to proceed?
Thanks!
Comment #24
brpubs CreditAttribution: brpubs commentedResolved, at least temporarily and for our web host's magic file, by adding the following line to the array of additional mimetypes in mimedetect.module:
'docx' => 'application/vnd.openxmlformats',
And by commenting out the attempt to use fileinfo first, right below that.
Comment #25
manuel.adanClosing this as outdated, feel free to re-open if you're still looking for a solution and waiting for appropriate assistance.