This project is read-only.

The file sample.docx cannot be opened because there are problems with the contents.

Apr 13, 2012 at 3:36 AM
Edited Apr 13, 2012 at 3:37 AM

I'm using PHPWord for my website developed with CakePHP. Everything's ok when I tested the PHPWord function at localhost. But after I hosted the website at the server, when I try to open the downloaded .docx file, it gave me an error as the post title said. The details of the error is like:

Microsoft Office cannot open this file because some parts are missing or invalid.

I tried to save the file as .doc, the file can be opened but what I got is:

Fatal error: Class 'ZipArchive' not found in C:\wamp\www\mysite\app\vendors\PHPWord\PHPWord\Writer\Word2007.php on line 70.

Does it has something to do with the URL? Why did the error point to an URL that was actually refering to a localhost address?

I've googled around and found no solutions to the problem. I don't even know what the problem is! So somebody PLEASE HELP!

Apr 14, 2012 at 3:15 AM

I was so stupid that the problem was solved by just enabling the php_zip.ddl extension in php.ini. =  =

Jul 5, 2012 at 10:56 AM

Would you share with us how to integrated PHPWord to CakePhp?


Thanks before

Jul 6, 2012 at 11:30 AM
Edited Jul 6, 2012 at 11:30 AM


Just put the downloaded PHPWord folder in the app/vendors folder, and in your function include the main file (as shown below):


function your_function() {


        $PHPWord = new PHPWord();

        $section = $PHPWord->createSection(array('borderColor'=>'00FF00', 'borderSize'=>12));
	$section->addText('I am placed on a default section.');

        // New landscape section
	$section = $PHPWord->createSection(array('orientation'=>'landscape'));
        $section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');

        // New portrait section
	$section = $PHPWord->createSection(array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600));
	$section->addText('This section uses other margins.');

        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=your_file_name.docx");
        header("Content-Type: application/docx");



You can find more examples in the PHPWord folder on how to put contents into Word file and how to style them as well.




Jul 24, 2012 at 5:08 AM

Thank you very much Feehilies.S.


Your information very-very help us..


Best Regards.,


Aug 6, 2012 at 12:04 PM


I have encoutered same problem "Microsoft Office cannot open this file because some parts are missing or invalid."


But as you solved with enabling php_zip.ddl, i cant find such thing.

My phpinfo (PHP Version 5.2.17) shows this:


Zip enabled
Extension Version $Id: php_zip.c ...
Zip version 1.8.11
Libzip version 0.9.0


Is the version too old or what? 

I use both MS office and Libre office, and the file opens only on libre office.

Aug 8, 2012 at 11:19 AM


I'm not sure about the version, but the php.ini file in which the php_zip must be enabled is on the web server, not on the php server. Like in my case, it's Apache.




Aug 10, 2012 at 9:06 AM

ok, thanks for the info.