Miten Patel
Miten Patel

Reputation: 121

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.

Upvotes: 3

Views: 7012

Answers (1)

Thamaraiselvam
Thamaraiselvam

Reputation: 7080

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());

Upvotes: 4

Related Questions