简体   繁体   English

如何在 PHP 中保存 doc 文件?

[英]how to save a doc file in PHP?

This is my example.php , using this i am generating a example.doc file and using header i can save that file in my local computer.这是我的example.php ,使用它我生成一个 example.doc 文件并使用标题我可以将该文件保存在我的本地计算机中。

But i want to save one more copy in report folder ( report and example.php are in same folder/same domain )但我想在报告文件夹中再保存一份副本(报告和 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");

?>

You need to add你需要添加

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

instead of代替

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM