Forum


Replies: 1   Views: 3296
Word complains that i have a corrupted docx file
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 koopie66  · 05-10-2017 - 18:19

Hi.

Hi installed phpdoc the trial version to see if it fits my needs. I created a document, but when I save it and I ant to open it it tells me that the file is corrupt.

If I download the file via FTP I don't get this error. I also noted that the downloaded file has a bigger size than the file via FTP

I use the following code to perform a download

=====

header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
    header('Content-Disposition: attachment; filename="document.docx"');
    header('Expires: 0');
    header("Content-Length: " . filesize('document.docx'));
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    ob_clean();
    flush();
    readfile('document.docx');

 Can you please give some help in how to solve this issue, its really blocking my evaluation of your software

Kind regards Hans

 

Posted by admin  · 05-10-2017 - 18:33

Hello,

The most common problem when getting a corrupted DOCX is that your server is not returning a correct mime type or your server is adding information to the document.

Please check the documentation available about how to download a DOCX file using phpdocx:

https://www.phpdocx.com/documentation/cookbook/download-generated-docx

phpdocx includes a createDocxAndDownload method to generate and download the documents, and you can try the alternative code available on the previous page. Premium licenses also include a stream mode to download the DOCX directly without saving the document to the filesystem.

And also please check this recent issue and how it was resolved:

https://www.phpdocx.com/en/forum/default/topic/1463

Regards.