class ZipCreate{
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files) {
$zip->addFile($file_path.$files,$files);
}
$zip->close();
chmod($archive_file_name, 0777);
// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".basename($archive_file_name)."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($archive_file_name));
ob_end_flush();
@readfile($archive_file_name);
}
}
上面的代码在本地工作正常,它正在本地unix系统中正确下载zip文件。应在其中创建zip的文件夹具有777权限。但是在本地的Windows系统和在线服务器上它会给出网络错误..任何人都可以告诉上面的代码中可能存在什么问题。