-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cannot update a docx containing an image #1212
Comments
I forgot to mention that the initial exception is this one:
I applied the following changes, which gets a step further, but still fails to close the document (Exception described above):
|
what if you add the sections inside a function block? (so that variables get undefined when the function ends) |
Actually, the error also happens in a batch, where a JS function requests a
page, which triggers the PHP code. So the request ends, and no variables
are kept.
It works fine with just text. It also works if the first few batch calls
only add text, then one call adds an image. The next call will then fail,
regardless if we add text or an image.
|
@wadmiraal could you give it a try with the dev-develop version, just to make sure this is still valid? |
I just tried again with the latest dev-develop branch. Clean install in another folder, called I then modified I then created the following PHP file in the root of the PHPWord repo (
Note: Make sure I then executed it like this: Stack trace:
|
Experiencing same problem after adding image. I am adding image like this: And when trying to do it second time it errors out: Invalid image: zip:https://F:\WEB\xampp\htdocs\workflow\storage/app/files/FILENAME.docx#word/media/section_image1.jpg |
I need to generate a pretty large Word document, with lots of data from a database.
Instead of fetching all the data in one go, and risking a timeout, I fetch a set number of elements at a time, and process the document in a batch.
A very crude simplification would look like this:
So far so good.
However (and I've been banging my head for hours now), if at one point I add an image, I can no longer update the document. It will throw an exception: Could not close zip file, and PHP throws the following warning: ZipArchive::close(): Invalid or uninitialized Zip object.
If I use PeclZip, it will not throw any error, but the file won't be readable.
Expected Behavior
I would expect a document to be loaded correctly, and then be save-able again. This is the case as long as no image is added.
Current Behavior
If the document contains an image, it can be opened, but not updated.
I tried copying the file prior to opening it, renaming it, to no avail. I checked file permissions, but it doesn't seem to matter. I updated the user:group of the webserver to make certain it wasn't that either: no success.
Failure Information
\PhpOffice\PhpWord\Exception\Exception
thrown: Could not close zip file (in\PhpOffice\PhpWord\Shared\ZipArchive::close()
)PHP warning: ZipArchive::close(): Invalid or uninitialized Zip object
How to Reproduce
Running this code triggers the error (I'm on the latest dev commit):
Context
The text was updated successfully, but these errors were encountered: