zip_read strangeness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Hallert

    #1

    zip_read strangeness

    Hi!

    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($fileli st as $filename)
    {
    if (($temp = zip_open($local _storage.$filen ame)))
    {
    while ($entry = zip_read($temp) )
    {
    $file_name = zip_entry_name( $entry);
    $file_size = zip_entry_files ize($entry);
    $compression = zip_entry_compr essionmethod($e ntry);

    echo "Contains: $file_name ($file_size) compressed with
    $compression.\n ";

    //Do stuff
    }
    zip_close($temp );
    }
    }

    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?

    Thanks!

  • zorro

    #2
    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...

    Comment

    • Ben Hallert

      #3
      Re: zip_read strangeness

      zorro wrote:
      Tried your script and it works fine, though at first it wasn't working
      because i had relative paths in filenames...
      Hmm, if the logic is ok, maybe something is weird with my environment.
      Thanks!

      Comment

      • Ben Hallert

        #4
        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.
        Whooops....

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

        Regards,

        Ben

        Comment

        Working...