我正在使用此代码生成word文件并从浏览器下载。这是在chrome中工作,但在firefox中不起作用 下载文件但没有扩展名。
$this->loadModel ( 'Template' );
$template = $this->Template->findById ( $template_id );
$doc_body = $template['Template']['content'] ;
header("Content-Type: application/vnd.msword");
header("Expires: 0");//no-cache
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//no-cache
header("content-disposition: attachment;filename=".$template['Template']['title'].'-'.time().".doc");
echo "<html>";
echo "$doc_body";
echo "</html>";
die;
答案 0 :(得分:1)
请尝试将其作为代码的一部分。
$filename = $template['Template']['title'].'-'.time().".doc";
header("content-disposition: attachment;filename=\"$filename\"");