我已经实现了以pdf格式导出报告的功能。
以下是代码:
$dompdf_config = new DOMPDF();
$template = new Template();
$template->data['products']=$results;
$html = $template->fetch('report/business_pdf.tpl');
$dompdf_config->load_html($html);
$dompdf_config->set_paper('letter', 'portrait');
$dompdf_config->render();
if (file_put_contents('report.pdf', $dompdf_config->output()) !== false) {
$this->redirect('report.pdf');
}
但它会在浏览器中打开,那么如何强制下载呢?
更新
之后我添加了代码:$file = "report.pdf"
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
获取下载对话框:
对话框中没有打开选项,请帮帮我