I am working on a document that requires a user to upload a Microsoft Word Documents.
Apart from checking the file extension to be .doc or .docx, is there any other way i can verify that the uploaded file is actually a Microsoft Word Document and not any other file renamed to a .doc or .docx extension.
Thanks in advance.
If your are not using PHP 5.3, the mime_content_type function might interest you.
If you are using PHP 5.3 and/or can install PECL extensions, the new Fileinfo library should do the job ; see finfo_file for more informations.
In the given example, one of the identified mime types is "application/vnd.ms-excel" ; so, with a bit of luck, it should be able to deal with MS Word files too ;-)
.docx is a set of XML files that have been compressed using the standard zip compression scheme. So you could try passing it to an unzip algorithm and seeing if it decompresses, and then attempt to look at the proper xml file within and check for fields that one would expect to find in a document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With