Wednesday, May 30, 2018

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...