Jump to content

trouble using unzip.lib.php to extract zip archives


webhead2

Recommended Posts

I am testing the following code:  Notice I am try three techniques to extract the file:

 

require_once("zip.lib.php");
require_once("unzip.lib.php");

$file = "incoming_data/marketplace_feed_v1.xml.zip";

// first attempt, no work
system("unzip $file -d /incoming_data/"); 

// second attempt, dopes not work either
exec($file);

// third attept, works but encoded output

$zip = new SimpleUnzip();
$filename = $file;
$entries = $zip->ReadFile($filename);

foreach ($entries as $entry){
     $fh = fopen($entry->Name, 'w', false);
    fwrite($fh,$entry->Data);
    fclose($fh);
}

 

The first two attemot out put nothing, the third (SimpleUnzip) unzips the files, but the contents are encoded like this:

 

̽ÛrãØÑ.x燎lu»»L¢ˆm{Àƒ$vñÔ$UêòŽ; ’àš

 

Any help is appreciated.

 

I've check the integrity of marketplace_feed_v1.xml.zip.  I've downloaded it and it unpacks nicely.

 

I'm running, Linux, Apache, VPS.

 

I took my code straight from the PHP manual.  Thanks for your help!

Link to comment
Share on other sites

Yes, i am trying to extract all of the files, that's it.

 

I tried this:

 

$file = "incoming_data/marketplace_feed_v1.xml.zip";

 

$zip = new ZipArchive;

if ($zip->open('incoming_data/marketplace_feed_v1.xml.zip') === TRUE) {

    $zip->extractTo('/incoming_data/');

    $zip->close();

    echo 'ok';

} else {

    echo 'failed';

}

 

I GET NOTHING, no message, no files

Link to comment
Share on other sites

Thanks for your help.

 

system("unzip $file -d incoming_data/");

 

This works.  It was dumping the files into root. 

 

I thought I had tried both, but you know how it goes when you get waist deep in code.

 

Thanks again for the extra pair of eyeballs.

 

I wonder, is there a way to test if this function is enabled on the server?  Will most servers have this functionality installed by default?  I ask because I am making an installer.

 

system("unzip $file -d incoming_data/");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.