[英]PHP ZipArchive gives Invalid or uninitialized Zip object error on extraction
I'm having trouble extracting file some files from zip using ZipArchive我无法使用 ZipArchive 从 zip 中提取文件
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
如果我检查
$res
变量,它会返回19
,这很奇怪,它应该是TRUE
或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.这是在 WordPress 后面完成的,我试过
$_SERVER['DOCUMENT_ROOT']
和ABSPATH
无济于事。 I also tried with different zip files, still no luck.我还尝试了不同的 zip 文件,但仍然没有运气。
$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试试这个来源: https://stackoverflow.com/a/8889073/5717344
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.