Forum


Replies: 2   Views: 1571
Change mime content-type
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 LucasSpl  · 09-03-2021 - 08:46

Hello,

This simple script

$docx = new CreateDocx();

$docx->embedHTML('<h2 style="text-align: center;">test</h2>');

$path = DIR_TMP . getUniqId();
$docx->createDocx($path);

$path .= ".docx";

var_dump(mime_content_type($path));

 Return

string(24) "application/octet-stream"

I am using a pdf converter which is strict on the content type, and it refuses application/octet-stream.
Is it possible to get application/vnd.openxmlformats-officedocument.wordprocessingml.document ?

Regards

Posted by admin  · 09-03-2021 - 09:26

Hello,

UPDATE: phpdocx 14.5 reordered the default base template to return Microsoft Word 2007+ mime type using CreateDocx.

A DOCX file is a ZIP file, so application/octet-stream is a correct MIME for a DOCX file; ZipArchive, used to create the DOCX files, generates that mime. If you want to set other MIME you can use header functions from PHP when sending/downloading the documents (as createDocxAndDownload does) or you can try changing the magic setup in your server:

https://stackoverflow.com/questions/6595183/docx-file-type-in-php-finfo-file-is-application-zip

As you are using a Premium license, you can also use the stream mode (https://www.phpdocx.com/api-documentation/performance/zip-stream-docx-with-PHP).

If you are using an external service that requires application/vnd.openxmlformats-officedocument.wordprocessingml.document as mime type, we recommend you to contact them to know how to set other mime type to their service (as PHP header function allows).

Regards.

Posted by LucasSpl  · 09-03-2021 - 10:48

I will look at your solutions

Thanks !

 

Regards