Iam因PHP 5.2x和“ZipArchive”而变得疯狂,以下代码不会引发错误,每个部分都会返回true,但不会创建ZIP文件。来自文件夹的PHP Zip文件 - 无错误 - 无存档
有人能看到iam没有看到的错误吗?
if ($handle = opendir($directory)) {
$zip = new ZipArchive();
$filename = time() . '.zip';
$path = APPLICATION_PATH . '/../download/';
$status = $zip->open($path . $filename, ZIPARCHIVE::CREATE);
if ($status !== true) {
$this->log->err('Cant create zipArchive!');
return false;
}
while (false !== ($file = readdir($handle))) {
if (!is_dir($file)) {
if (is_readable($file)) {
if (!$zip->addFile($file)) {
$this->log->err('Cant add File to archive: ' . $file);
}
} else {
$this->log->debug('Added file to archive: ' . $file);
}
}
}
closedir($handle);
if (!$zip->close()) {
$error = $zip->getStatusString();
$this->log->err($error);
$this->log->err('Cant create archive..');
}
}
尝试输出''真实路径来检查,你在这里做不成问题($路径$文件名)。 。你也可以尝试输出'is_writable(realpath($ path))'来检查权限。 – Florent