php – 创建zip时没有错误,但没有创建

我写了这个代码来创建一个ZIP文件并保存它.但不知何故,它不会显示任何错误,但它也不会创建一个ZIP文件.以下是代码:

$zip = new ZipArchive;
$time = microtime(true);
$res = $zip->open("maps/zips/test_" . $time . ".zip",ZipArchive::CREATE);
if ($res === TRUE) {
    echo "RESULT TRUE...";
    $zip->addFile("maps/filename.ogz","filename.ogz"); //Sauerbraten map format
    $zip->addFromString('how_to_install.txt','Some Explanation...');
    $zip->close();
    $zip_created = true;
    echo "FILE ADDED!";
}

我做错了什么,我该怎么解决?

apache或php可能没有权限在该目录中创建zip存档.从
ZipArchice::open的评论之一:

If the directory you are writing or
saving into does not have the correct
permissions set,you won’t get any
error messages and it will look like
everything worked fine… except it
won’t have changed!

Instead make sure you collect the
return value of ZipArchive::close().
If it is false… it didn’t work.

在你的if语句中添加一个else子句并转储$res来查看结果:

if($res === TRUE) {
    ...
} else {
    var_dump($res);
}

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。