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