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!

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

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/");

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.