zip_read strangeness

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm using the zip functions for the first time and I'm having an odd
problem.  I may be doing something boneheaded, here's hoping someone
here can recognize it.

I have a foreach loop that goes through a list of files and is supposed
to generate a list of the contents.

foreach($filelist as $filename)
    if (($temp = zip_open($local_storage.$filename)))
        while ($entry = zip_read($temp))
            $file_name    = zip_entry_name($entry);
            $file_size    = zip_entry_filesize($entry);
            $compression    = zip_entry_compressionmethod($entry);

            echo "Contains: $file_name ($file_size) compressed with

            //Do stuff

It appears to work, but when I look at the output, I realize that the
info is correct for the _first_ file it iterates through, but each
subsequent file is just showing the same data from the first file
again.  I've verified that the zip contents are different.  I've tried
manually clearing the strings involved, played around with
zip_open_entry, and so on, but it keeps repeating the info from the
first zip as the data for the rest.

It's late here, maybe I'm missing something obvious.  Can anyone tell
me why it might behave like this?


Re: zip_read strangeness

Tried your script and it works fine, though at first it wasn't working
because i had relative paths in filenames...

Re: zip_read strangeness

zorro wrote:
Quoted text here. Click to load it

Hmm, if the logic is ok, maybe something is weird with my environment.

Re: zip_read strangeness

(forehead slap)

I just figured it out.

I had trimmed the foreach loop from my original code snippet when I put
it in, then, realizing it would help make it readable, I put it back.
...but instead of putting it back intact, I just retyped it from
memory.  It turns out that my foreach loop pushed out a different
variable name, but the $filename string I was using was leftover from a
few lines before.

So, local namespace variables might havesaved my from my own stupidity.
 The code works when I actually pass it a variable name that changes.

On the plus side, there's code on Google Groups showing how to read out
the contents of a zip from PHP now, heh.



Site Timeline