【问题标题】:how to save a doc file in PHP?如何在 PHP 中保存 doc 文件?
【发布时间】:2018-02-06 06:23:12
【问题描述】:

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

但我想在 report 文件夹中再保存一份(report 和 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");

?>

【问题讨论】:

    标签: php header doc


    【解决方案1】:

    你需要添加

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

    而不是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多