Forum


Replies: 3   Views: 3519
Phpdocx error while trying to open a template
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 legalvorce  · 03-08-2017 - 15:37

I have downloaded phpdocx and I am testing my code on my local environment. I can successfully create a document from scratch with the following code:

$docx = new \Phpdocx\Create\CreateDocx();

$docx->addText('This is a test');
$docx->embedHTML('<p style="font-size: 30px;">New paragraph</p>');
$docx->createDocx(public_path() . '/output.docx');

However, I am needing to create a document from a template. Everytime I do so though I get the following error message: Error while trying to open the (base) template as a zip file

Here is my code:

$docx = new \Phpdocx\Create\CreateDocxFromTemplate(public_path() . '/Example Template.docx');

$variables = [
    '1' => 'John',
    '2' => 'Allen',
];

$docx->replaceVariableByText($variables);
$docx->createDocx(public_path() . '/output.docx');

Also, I am attaching a screenshot with more error details below:

https://i.stack.imgur.com/0jCEp.png

Posted by admin  · 03-08-2017 - 16:06

Hello,

It seems your server is not getting the path to the template, please try removing the blank space.

Regards.

Posted by legalvorce  · 03-08-2017 - 16:53

Hello,

Thanks for the suggestion. I just tried that and unfortunately I am still receiving the same error message. Any other suggestions?

Posted by admin  · 03-08-2017 - 19:09

Hello,

That error may appear if:

1. ZipArchive is not installed or enabled. As you can create the DOCX from scratch your server must have ZipArchive installed.

2. The server can't read the DOCX file due to missing read access or it doesn't exist.

3. Some file is missing in the phpdocx folder.

4. The DOCX file you are trying to use as template is not a valid DOCX but a DOC or other document format.

Please run one of the included samples in the examples/Templates/replaceVariableByText folder using PHP CLI mode.

Regards.