Asked 7 years ago
29 Dec 2016
Views 1097

posted

how to extract zip file in php ?

how to extract zip file in php ?
is there any lib or code to extract zip easily without more complex code
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

there is lots of library and open source help available to zip or unzip .
use plczip to do extraction of zip in php .

plczip


$archive = new PclZip($file);
$archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);


wordpress also use plczip to do zip work
function _unzip_file_pclzip() is used to extract zip file in wordpress

Full documentation about PclZip can be found here : http://www.phpconcept.net/pclzip
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

ZipArchive is core php class which do all zip related work .

$zip = new ZipArchive();
$filename = "test.zip";

if ($zip->open($filename)!==TRUE) {
    die("cannot open <$filename>\n");
}

or use zip_open function

$zip = zip_open("/tmp/test2.zip");

if ($zip) {
    while ($zip_entry = zip_read($zip)) {
    // do something  
    }
}




$zip = new ZipArchive;
    $zip->open('test.zip');
    $zip->extractTo($destination_folder);
    $zip->close(); 
Post Answer