Friday, June 22, 2012

How to Unzip Zip file in PHP

6/22/2012


If you dont have access or cpanel access to your server and need to unzip an archive of zip file on your php server. You can use the script below to unzip files on your server using php:
$_ZIP_FILE = zip_open('file.zip');
while ($zip_entry = zip_read($_ZIP_FILE)) 
{
 $name = zip_entry_name($zip_entry);
 if (substr($name, -1) == '/') {
  mkdir($destination . $name);
 } else {
  $fh = fopen('zip/' . $name, 'w');
  if (zip_entry_open($_ZIP_FILE, $zip_entry, 'r')) {
   $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
   fwrite($fh, $buf);
   zip_entry_close($zip_entry);
  }
  fclose($fh);
 }
}
zip_close($_ZIP_FILE);

Above script will extract all the contents of the zip archive in the target directory, so no worries when you have no cpanel or shell access. We still have solution for your problem

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top