网页下载
1 下载压缩文件
$tmp_name = time();
$filename = BASEPATH . "public/zip/".$tmp_name.".zip";
$ouput_name = '订单号:616565116.zip';
$img = '素材图片地址';
$content = 'txt内容';
$zip = new ZipArchive();
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("无法打开压缩文件!");
}
$zip->addFromString("设计要求.txt",$content);
$zip->addFile(BASEPATH . "public/zip/avatar.jpg",'素材1.jpg');
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$ouput_name.'"');
readfile($filename);
unlink($filename);
2 下载excel文件
$this->load->library('PHPExcel');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getSheet()->setCellValue('A1', 'PHPExcel');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
ob_end_clean();
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="资金交易记录.xlsx"');
$objWriter->save('php://output');