Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ziparchive error when phpword templateprocessor called #657

Open
guiramadasa opened this issue Nov 8, 2015 · 7 comments
Open

ziparchive error when phpword templateprocessor called #657

guiramadasa opened this issue Nov 8, 2015 · 7 comments

Comments

@guiramadasa
Copy link

guiramadasa commented Nov 8, 2015

Hi,

I am trying to replace some content in a word file, using following code.

<?php      
 require_once 'includes/PhpWord/Autoloader.php';
 \PhpOffice\PhpWord\Autoloader::register();

if($ext == 'docx')
     $phpWord = \PhpOffice\PhpWord\IOFactory::load($target_file);
else if($ext == 'doc')
    $phpWord = \PhpOffice\PhpWord\IOFactory::load($target_file, 'MsDoc');     

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($target_file);
?>

But it gives following errrors.

Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in /home2/xxx/public_html/xxx/FL/xxx/sc/includes/PhpWord/Shared/ZipArchive.php on line 198

Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in /home2/xxx/public_html/xxx/FL/xxx/sc/includes/PhpWord/Shared/ZipArchive.php on line 201

The file path is correct and also the solution needs to support both *.doc and *.docx formats.

It will be a great help if you can support me on this.

Thank you.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@guiramadasa
Copy link
Author

When checked files with is_readable(), it is readable, but get above error.

@ozilion
Copy link
Contributor

ozilion commented Nov 9, 2015

As I know you can only use .docx format for temaplate files.

@philippfrenzel
Copy link

Hi, did you find a solution, I try to read the file from an file abstraction layer which returns sadly doesn't work at all, now I tried to create a temporary file for processing, but still doesn't work:( Thanks

@erpwebadmin2
Copy link

Has anyone made .DOC file work on templateprocessor?

@arifulhb
Copy link

arifulhb commented Feb 9, 2021

Still didn't find a solution for .doc format.

@PoojaJadav
Copy link

I'm facing the same issue. I have a DOC file. It is readable as well. I got Invalid or uninitialized Zip object error.

I tried to loading format change as well with MsDoc. but still not woking. Can you please support to here :)
Thanks!!!

@MolbioUnige
Copy link

This happended to me, the problem was due to the line endings in the doc file. My server runs on linux, my doc file was saved with LF line ending, but pulling the repo changed the line endings to CRLF.
I solved it by specifying in .gitattributes that the doc(x) files where to be considered as binary.

*.doc binary
*.docx binary

The problem disappeared.

You can check the line endings of your file using

cat -e yourfile

If lines end with M$ you have CRLF line endings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants