Replies: 1   Views: 2096
File type issue
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by lewisrblack  · 17-02-2016 - 15:34

When I return the type of a generated docx file, using the following;

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $filepath);

It returns application/zip

When I run the same code on a docx generated from microsoft word, i get;


This is causing me issues, as I am posting the generated files to a third party API which is rejecting the docx file generated using PHPDocx. Is there any way around this?

Posted by admin  · 18-02-2016 - 08:01


This issue is due to how mime types work. Files don't have mime types and they are identified by their file extensions (the mime types are set by file extensions in /etc/mime.types).

And a DOCX is a ZIP file so if your OS is reading the header to get the MIME TYPE it may get a generic MIME:

Zip archive data, at least v2.0 to extract

this is due to how the ZIP has been generated, using ZipArchive with PHP. If you extract the ZIP and compress the files using the zip command on Linux you may get other MIME TYPE:

Microsoft OOXML

or even:

Microsoft Word 2007+

And it may vary if the file has been generated with Word or LibreOffice.

All these files are opened correctly with Word (and also LibreOffice or OpenOffice).

The solution to this issue is to send the correct MIME type header when you send the DOCX, this is setting the Content-Type value. The API you're using should have an option to set a MIME TYPE manually or force it using a header from your server.