[英]php zip extract makes file empty
Ok so this is making me crazy... I abstracted the code because it comes from a big project.好的,这让我发疯了……我抽象了代码,因为它来自一个大项目。 But in my project I ended up commenting everything and only have this left which is still causing problems and I have no idea why.
但在我的项目中,我最终评论了所有内容,只剩下这个仍然导致问题,我不知道为什么。
$f = fopen('tmp/'.$name.'.zip', 'wb');
fwrite($f, $myzip);
fclose($f); //I can open this file manually and everything is fine
$zip = new ZipArchive;
$res = $zip->open('tmp/'.$name.'.zip'); //$res is "1"
$zip->extractTo("final/" . $unique);
$zip->close();
As you can see I write a zip file in /tmp
, at this point, I can open the file manually and it contains all files with the correct size.如您所见,我在
/tmp
中编写了一个 zip 文件,此时,我可以手动打开该文件,它包含所有大小正确的文件。 But after I extract it to /final
, for some reason some files are empty... Any idea what could cause this?但是在我将它提取到
/final
之后,由于某种原因,有些文件是空的......知道什么可能导致这种情况吗?
You can do this way by throwing Exception at zip archive open time,您可以通过在 zip 存档打开时间抛出异常来做到这一点,
function DecompressFile()
{
$zip = new ZipArchive;
if ($zip->open('tmp/'.$name.'.zip') === TRUE) {
$zip->extractTo("final/" . $hwidDir);
$zip->close();
return 'completed';
}
else {
throw new Exception ("Decompress operation from ZIP file failed.");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.