Extracting (unzip) with PHP ZipArchive::open

The default command (without flag) to open ZIP archives seems not to work in PHP in some cases. Try to use the following code instead.

<?php
$zipFile = "./anyfolder/filename.zip"; // Local Zip File Path
$zip = new ZipArchive;
if ($zip->open($zipFile, ZIPARCHIVE::CREATE) === TRUE ) {
    $zip->extractTo('./anyfolder');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

Make sure that you have the required read/write permissions.

Back to Top