php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39231 Problem with reading of .ZIP file content
Submitted: 2006-10-23 09:13 UTC Modified: 2006-10-23 15:37 UTC
From: lajbr at seznam dot cz Assigned: pajoye (profile)
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.6 OS: Windows 2003 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lajbr at seznam dot cz
New email:
PHP Version: OS:

 

 [2006-10-23 09:13 UTC] lajbr at seznam dot cz
Description:
------------
I found a serious problem on PHP 5.1.6 (5.1.4 too). I try to read content of .ZIP file (part of code is added below). I open an existing ZIP file and I want to read its content. But Warning message with following text is appeared (text is added below). The same problem occured when I use function zip_close(). As the result nothing is happened (no content from ZIP file is readed). When I go back to PHP version 5.0.5  then all works fine.

Reproduce code:
---------------
function ziplist($zipfile){
  $retval = array();
  if ($sourcezip = @zip_open($zipfile)) {
    while ($zip_entry = zip_read($sourcezip)) {
      array_push($retval,array('filename' => zip_entry_name($zip_entry),
                               'filesize' => zip_entry_filesize($zip_entry)));
    }
    zip_close($sourcezip);
  } else return false;
  return $retval;
} 

Expected result:
----------------
Warning: zip_read() expects parameter 1 to be resource, integer given in C:\Inetpub\wwwroot\epo\include\function.php on line 439

Warning: zip_close() expects parameter 1 to be resource, integer given in C:\Inetpub\wwwroot\epo\include\function.php on line 443


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-23 09:21 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-10-23 12:39 UTC] pajoye@php.net
Also which Zip extension do you use? (See phpinfo, $id and version).

If the problem persists with 5.2.0 or a recent version (get the latest DLLs on http://pecl4win.php.net), please provide a link to the zip file you use in this test.
 [2006-10-23 12:46 UTC] lajbr at seznam dot cz
I tried to use the latest snapshot from mentioned link but with the same result. In PHP 5.2-latest there is the same problem like in PHP 5.1.6 and 5.1.4.
 [2006-10-23 12:49 UTC] pajoye@php.net
I still need a Zip file to reproduce your problem.
 [2006-10-23 13:47 UTC] lajbr at seznam dot cz
Try to look at http://ambruz.webz.cz/problem.zip
Inside this zip are stored:
* ziptest.php ... script with phpinfo and tested function
* test.zip ... problem Zip file
* result.htm ... output with Warning messages and output of phpinfo.

I tried the latest files from pecl too but without effect.
 [2006-10-23 14:11 UTC] pajoye@php.net
You are doing something wrong in your script.

I tried using 5.1.6, 5.2.0, 6.0 and with the latest pecl4win dll using this script:
$zipfile = 'bug39231.zip';
if ($sourcezip = zip_open($zipfile)) {
    while ($zip_entry = zip_read($sourcezip)) {
        echo 'filename: '. zip_entry_name($zip_entry) . " ";
        echo 'filesize: '. zip_entry_filesize($zip_entry) . "\n";
    }
    zip_close($sourcezip);
} else {
    echo "Cannot open zip";
}


C:\php-5.1.6>php.exe bug39231.php
filename: result.htm filesize: 55457
filename: test.zip filesize: 131347
filename: ziptest.php filesize: 599

It works like a charm (and as expected). Be sure to load the correct php_zip.dll or to have restarted your server after a dll update.
 [2006-10-23 15:13 UTC] lajbr at seznam dot cz
Thank you for your help. We found a mistake in our side but this behaviour of PHP is very strange. We have missing extension of the file and PHP 5.0.5 probably automatically added correct extension to the filename internally. PHP 5.2.0, 5.1.6 and 5.1.4  returns this Warning in another zip functions. 
It's very interesting that according to the manual function zip_open() have to return false when file doesn't exist or resource id. In the fact (from PHP 5.1.4 and above) if file doesn't exist then function zip_open()returns 11, returns 19 if it isn't Zip file and resource id in other cases. This is strange behaviour because everybody expects that zip_open() returns false when whichever error occures.
 [2006-10-23 15:37 UTC] pajoye@php.net
PHP 5.0.5 contains an old version of the zip extension. It was read only and with some limitations in the amount of supported zip formats.

The new version is a complete rewrite, supports the creation, modification and read of Zip files, adds a OO interface and many more features.
Check the php manual for a full list of changes (http://www.php.net/zip).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 16:01:30 2024 UTC