php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41456 Cannot decompress newly added files
Submitted: 2007-05-21 12:49 UTC Modified: 2010-12-20 14:21 UTC
From: sander dot marechal at tribal dot nl Assigned: pajoye
Status: Assigned Package: Zip Related
PHP Version: 5.2.2 OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-05-21 12:49 UTC] sander dot marechal at tribal dot nl
Description:
------------
When I add or update a file in the zip archive, I cannot read the new file without closing and reopening the archive first.

If this turns out to be a limitation in zlib then I suggest that a ZipArchive::flush() method of some sorts is added which can be called between a write and a read to produce the expected result.

Reproduce code:
---------------
#!/usr/bin/php -q
<?php

// Please make sure a dummy test.zip exist before running this code

$zip = new ZipArchive();
$zip->open('test.zip');
$zip->addFromString('test.txt', 'some text');
echo "Before: " . $zip->getFromName('test.txt') . "\n";

$zip->close();
$zip->open('test.zip');
echo "After: " . $zip->getFromName('test.txt') . "\n";

?>

Expected result:
----------------
Both the 'before' and 'after' should output 'some text'.

Actual result:
--------------
'before' is empty. Only 'after' shows 'some text'.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-23 22:14 UTC] pajoye@php.net
All operations (delete, comments, etc.) are applied to the zip file on close, not only the added files. It allows undo, sanity checks as well as a couple of improvements in the final zip files.


"// Please make sure a dummy test.zip exist before running this code"

Use the creation mode :)
 [2007-05-24 07:30 UTC] sander dot marechal at tribal dot nl
In that case, can't ZipArchive detect I'm trying to read a file that has pending operations and read from it's internal cache instead of from the file?

Alternatively, would it be possible to add a ZipArchive::flush() method which applies all pending operations, so I can safely read from it afterwards?

My PHP application processes a lot of ODF files, which are essentially ZIP containers. So, I pass around a lot of ZipArchive instances by reference. I usually can't close and reopen the file because I don't have the filename around but just the ZipArchive instance.
 [2007-05-24 09:07 UTC] pajoye@php.net
"Alternatively, would it be possible to add a ZipArchive::flush() method which applies all pending operations, so I can safely read from it afterwards?"

A flush method is in my todo, that's why I changed this bug status to a  feature request :)

"I don't have the filename around but just the ZipArchive instance."

I realize that the filename propriety does not always work. It should contain the filename of the Zip archive (not sure when it changed, more about this problem later). But it is what you may use as a temporary solution.
 [2010-12-20 14:21 UTC] jani@php.net
-Package: Feature/Change Request +Package: Zip Related
 [2016-03-19 02:34 UTC] david dot proweb at gmail dot com
@pajoye Do you have some solution to this case? Seems simple just return the content stored on memory. Thanks!
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC