Search code examples
phpphp-ziparchive

PHP: ZipArchive::extractTo doesn't working (Errror)


I'm completely at a loss for explaining why this isn't working.

$filename = 'zipfile.zip';
$za = new ZipArchive();
$folder = DIR_UPLOAD . $filename;
$za->open($folder);
$za->extractTo(DIR_UPLOAD . 'unzip/');
$za->close();

Error: ZipArchive::extractTo(): Invalid or uninitialized Zip object

I tried so many solution for solving this error, But i still facing this error.


Solution

  • Warning: ZipArchive::extractTo(): Invalid or uninitialized Zip object

    Means your zip path is wrong. Check your DIR_UPLOAD

    This script works fine for me

    $filename = 'sample.zip';
    $za = new ZipArchive();
    $folder = $filename;
    $za->open($folder);
    $za->extractTo('unzip/');
    $za->close();
    

    also set the right file permission for unzip folder.

    add these lines end of the code and see the last error

    echo "<pre>";
    print_r(error_get_last());