Friday, 21 July 2017

How to unzip a zip folder using php code





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?


Answer



$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);
}

?>

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...