问题描述
我正在使用 Laravel 5.8,我正在使用 PHPword 创建 .rtf 文件。 当我下载它时,它以 zip 文件的形式打开。我将文件类型 rtf 更改为 docx,但得到了相同的结果。
解决方法
使用下面的代码,我可以设法将文件下载为 RTF 而不是 Zip 存档。
好的,现在我可以设法用波纹管代码解决它
############## Create RTF file ##############
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord,'Word2007');
$objWriter->save(public_path('Report_File/InfoSec_DFAR_Report_' . $time . '.rtf'));
############## Create RTF file ##############
############## Download RTF file ##############
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/rtf");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize(public_path('Report_File/filename' . $time . '.rtf')));
header("Content-Disposition: attachment; filename=InfoSec_DFAR_Report_".$time. '.rtf');
readfile(public_path('Report_File/filename' . $time . '.rtf'));
die();
############## Download RTF file ##############