Re: unzip a file - destination folder wrong

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Shawn McKenzie wrote:
Merlin Morgenstern wrote:
Hi there,

I am trying to unzip a zip file. Therefore I am using this function:

# unzip a file
function extract_zipfile($filename){
    $zip = zip_open($filename);
    if ($zip) {
      while ($zip_entry = zip_read($zip)) {
        $fp = fopen(zip_entry_name($zip_entry), "w");
        if (zip_entry_open($zip, $zip_entry, "r")) {
          $buf = zip_entry_read($zip_entry,
zip_entry_filesize($zip_entry));
          fwrite($fp,"$buf");
          zip_entry_close($zip_entry);
          fclose($fp);
        }
      }
      zip_close($zip);
    }
}

It works, but unfortunatelly the extracted files are all placed into the
directory where the php file is located. Not where the original zip file
was found. I tried to add the directory to fwrite, but without success.

Does somebody know where to specify the target directory?

Thank you for any help,

Merlin

Try this:

$fp = fopen(dirname($filename) . '/' . zip_entry_name($zip_entry), "w");


thank you this worked. How come the . '/' . zip_entry_name($zip_entry) is needed? Looks like a double file name, but the result is ok. Could you explain this line? Thank you!

Kind regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux