Jump to content

Problems with zip_read


weezelds

Recommended Posts

Hello,

I'm having trouble with zip_read.  I made a zip of 2 plain 8k text files and zipped them w/ winrar using default settings.  I opened the file w/ zip_open and then checked to make sure the return value was a valid resource, which it is.  But when I try to use the return value of zip_read I get:

Warning: zip_entry_name() expects parameter 1 to be resource, boolean given in xxx

It is actually returning "1".  According to the zip error codes I think this means "Multi-disk zip archives not supported".  I have no idea what a 'multi-disk' zip file is.  I've posted my code below. 

 

How can I get php to read through a zip file?

 

Thanks

 

       
        $zip = zip_open($this->upload_path . $filename);
        if (is_resource($zip)) {
       	  $i = 0;
       	  while($zip_entry = zip_read($zip) && $i<500 ){
       	  	if($this->debug) echo "zip_entry=" . $zip_entry . "<br>";
       	  	$basename = basename(zip_entry_name($zip_entry));
       	  	$zipped_file = $this->upload_path . $basename;
                // other unrelated code
          }
        }

Link to comment
https://forums.phpfreaks.com/topic/250973-problems-with-zip_read/
Share on other sites

while($zip_entry = zip_read($zip) && $i<500 ){

 

That does not do what you expect. The condition is run such as $zip_entry = (zip_read($zip) && $i<500), in other words $zip_entry will be assigned the result of the && condition, which is going to be either bool(true) or bool(false). 

 

You need to put parenthesis around the assignment to make sure it is run correctly.

 

while(($zip_entry = zip_read($zip)) && $i<500 ){

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.