Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unzip a zip folder using php code [duplicate]

Tags:

php

zip

unzip

I want to unzip directorires.

That means i have a zipped directory name with xxx.zip.In manuall i right clicked on the zipped directory and do extract folder,then i got an unzipped dirtectory with name xxx and also in this directory have a same directory xxx.In the subfolder will contained the files.

That means, xxx->xxx->files this is the heirarchi of unzipped folder.

So in my site i want to unzipp a directory using php code.

How can i do this? I need only xxx->files not xxx->xxx->files structure.

How can i do this?

like image 393
Kichu Avatar asked Jan 23 '12 05:01

Kichu


2 Answers

<?php
$zip = zip_open("zip.zip");
if ($zip) {
  while ($zip_entry = zip_read($zip)) {
    $fp = fopen("zip/".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);
}
?>
like image 65
Tarun Baraiya Avatar answered Sep 18 '22 08:09

Tarun Baraiya


See this http://www.php.net/manual/en/ziparchive.extractto.php

$zip = new ZipArchive;
if ($zip->open('E:\pathto\zip\ashok_subedi.zip') === TRUE) {
    $zip->extractTo('E:\pathto\extrac\myzip');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
like image 40
asok Buzz Avatar answered Sep 22 '22 08:09

asok Buzz