I'm having trouble extracting file some files from zip using ZipArchive
Here is my code
$pp_saved_zip_archive = "$extract_path/archive.zip";
$zip = new ZipArchive;
$res = $zip->open($pp_saved_zip_archive, ZipArchive::CREATE);
$zip->extractTo($previews_path);
$zip->close();
I get two errors/warnings in this code
PHP Warning: ZipArchive::extractTo(): Invalid or uninitialized Zip object in...
PHP Warning: ZipArchive::close(): Invalid or uninitialized Zip object in...
If I check for $res
variable it returns 19
, which is weird, it should be either TRUE
or FALSE
My paths are correct, so it's not a path problem. This is done behind WordPress, I've tried $_SERVER['DOCUMENT_ROOT']
and ABSPATH
to no avail. I also tried with different zip files, still no luck.
$result = $zipArchive->open("The archive you want to open");
if ($result === TRUE) {
$zipArchive ->extractTo("my_dir");
$zipArchive ->close();
// Do something else on success
} else {
// Do something on error
}
Try this Source: https://stackoverflow.com/a/8889073/5717344
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.