}
yii 框架下批量下载文件
bool ZipArchive::addFile ( string $filename
[, string $localname
= NULL
[, int $start
= 0 [, int $length
= 0 ]]] )
$zip = new ZipArchive(); $filename="attach_".uniqid().".zip"; $filepath="workflow_attachs/".$filename; if ($zip->open($filepath, ZIPARCHIVE::CREATE)!==TRUE) { exit('无法打开文件,或者文件创建失败'); } $attachs = WorkflowAttach::model()->findAll("wid={$wid}"); foreach($attachs as $item){ $datalist[]=$item['filepath']; } foreach( $datalist as $key=>$val){ if(file_exists($val)){
$val = @iconv("UTF-8","GBK",$val);
$key = @iconv("UTF-8","GBK",$key); //对于不同的系统进行转码,否则中文乱码
$zip->addFile($val,'显示的名称');
}
}
$zip->close();//关闭
if( !file_exists($filepath)){
exit("无法找到文件"); //即使创建,仍有可能失败。。。。
}