如何在PHP中保存doc文件?

时间:2018-02-06 06:23:12

标签: php header doc

这是我的example.php,使用这个我生成一个example.doc文件并使用标题我可以将该文件保存在我的本地计算机中。

但我想在报告文件夹中再保存一份副本(报告和example.php位于同一文件夹/同一域

<?php

 $html = preg_replace('%/[^\\s]+\\.(jpg|jpeg|png|gif)%i', 'http://www.asd.com\\0', $html);

    print "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"";
    print "xmlns:o=\"urn:schemas-microsoft-com:office:office\"";
    print "xmlns:w=\"urn:schemas-microsoft-com:office:word\"";
    print "xmlns=\"http://www.w3.org/TR/REC-html40\">";
    print "<xml>
     <w:WordDocument>
      <w:View>Print</w:View>
      <w:DoNotHyphenateCaps/>
      <w:PunctuationKerning/>
      <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
      <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
     </w:WordDocument>
    </xml>
    ";
    print '<h1>hello world</h1>';
    header( 'Content-Type: application/msword' );
    header("Content-disposition: attachment; filename=example.doc");

?>

1 个答案:

答案 0 :(得分:1)

您需要添加

header('Content-type: application/vnd.ms-word');

代替

header('Content-Type: application/msword');