我使用PHP Word
// Save File
$h2d_file_uri = tempnam( "", "htd" );
$objWriter = PHPWord_IOFactory::createWriter( $phpword_object, "Word2007" );
$objWriter->save( $filename ); // At this line, I would like to output the file to the browser
任何人都知道如何我可以输出文件到浏览器上的飞行?
下面的示例可能有效,但要在所有浏览器中获得预期的下载行为,Word2007的内容类型
标题必须正确。也许您需要一些额外的标题才能正确输出。
你可以试试这个:
$filename = "YOUR_Filename.docx";
header( "Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" );// you should look for the real header that you need if it's not Word 2007!!!
header( 'Content-Disposition: attachment; filename='.$filename );
$h2d_file_uri = tempnam( "", "htd" );
$objWriter = PHPWord_IOFactory::createWriter( $phpword_object, "Word2007" );
$objWriter->save( "php://output" );// this would output it like echo, but in combination with header: it will be sent
感谢@jamswidge:word2007的正确标题应该是application/vnd。OpenXMLFormatsOfficeDocument。文字处理ml.document
。
参考微软