我写了这个代码来创建一个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的评论之一:
原文链接:https://www.f2er.com/php/139914.htmlIf 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); }