3

I have a form to handle file uploads of restricted types (pdf, docx, etc) I had someone tell me they couldn't upload a docx. Oddly, other people can. So, I had the form show me the $mime_type for this particular file

$mime_type = mime_content_type($_FILES['input_name']['tmp_name']);

and it came back with this:

application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document

appears to be doubled up!? I ran some other docx files through it and they call came back as expected. Please can someone tell me what would cause this file type to be double?

Thank you

  • You should ask what their browser and version they are using is and the maybe the document as well if you can't reproduce otherwise. – Peter Krebs Jul 19 '22 at 09:27
  • Thank you. I did get the file from them, and ran the test using it (sorry if that wasn't clear enough above). Latest chrome browser version. File looks like a normal docx, but if I create other docx files I do not have the same issue. – user3541184 Jul 19 '22 at 13:27
  • Okay, then whatever `mime_content_type()` is doing is putting it twice in there or do you find such logic in your application somewhere? Otherwise I'll link to a question from SO with `Fileinfo` as an alternative. – Peter Krebs Jul 19 '22 at 14:13
  • 1
    See Fileinfo answer from here: [unrelated mime\_content\_type() question, but answer might help you](https://stackoverflow.com/questions/1263957/why-is-mime-content-type-deprecated-in-php) – Peter Krebs Jul 19 '22 at 14:14
  • 1
    Thank you. I tried Fileinfo, with the same result. This docx file shows "application/vnd.openxmlformats..." twice. Other docx files just once, as expected. I have added the double version as an accepted MIME type and it now allows the file to be uploaded. No idea what's going on, but thank you for your time. – user3541184 Jul 20 '22 at 07:50
  • Okay nice, so at least this workaround exists. Glad to help – Peter Krebs Jul 20 '22 at 07:58

0 Answers0