Link to home
Start Free TrialLog in
Avatar of Dean_Kletter
Dean_Kletter

asked on

PHP Function to unzip a zip file to a sub-directory

I'm trying to extract the contents of a zip package to a specific folder and keep getting an error.  I know the .zip package is good as I can open in from other programs.  This is php 5.2 so I know ZipArchive class is bundled.  Help???
Private $extractDir = './IMG/';

Private function download_pics ($dl_link){
	$zip = new ZipArchive;
	echo ('<br/>Start d/l Function');
	if  ($zip->open('./Test.zip') === true){
	  echo ('<br/>Start 1st Zip');
	  $zip->extractTo($extractDir);
	  $zip->close();
	  } ELSE {
  	  die("<br/>There was a problem unpacking the website .ZIP archive.");
	  }
  echo ('<br/>End Zip Functions');
  }

Open in new window

Avatar of ragnarok89
ragnarok89

is the php_zip.dll extension uncommented in your php.ini?
Can you please post te PHP Error
Avatar of Dean_Kletter

ASKER

I searched my php.ini and could not find a reference to php_zip.dll,  there was a mention of zlib but that appeared to be for uploading files.

I added:

extension=php_zip.dll

Still getting error, do I need to reboot?  Let IIS sit for 30 minute but did not restart services.

I have Error logging set to on and production level put nothing appeared but the error built into the code.
You need to restart the IIS,

You can verify the ZI functions are loaded, creating a file with
<?
echo phpinfo();
?>

And run it from internet explorer,
This show a list, with the status of PHP
and all the loaded plugins, here must be the ZIP libraries showed
It says it is enabled

 User generated image
ASKER CERTIFIED SOLUTION
Avatar of wmadrid1
wmadrid1
Flag of Colombia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That is nice.  I don't need to enumerate through the ZIP file, just expand the contents to a folder.  The code below is directly off the PHP Website but still the ZIP file fails verification somehow.  I know the zip is valid, as I can open in numerous archiving application but it still fails the boolean test.
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

Open in new window

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.