简体   繁体   English

如何使用PHP创建.DOC文件

[英]How to create .DOC file using PHP

This Question may be duplicate, but all I want to know that there is any way to create .doc not .docx file using PHP (Not COM) . 这个问题可能是重复的,但是我想知道有任何方法可以使用PHP (Not COM)创建.doc not .docx文件。 I've tried the following code to generate a file, It does but it is not a real .doc file , It is just a masked HTML file . 我尝试了以下代码来生成文件,它确实可以,但是it is not a real .doc file ,它只是一个masked HTML file Anybody please help me to create a REAL .doc file 有人请帮助我创建一个REAL .doc文件

Here is my Sample Code (it generates .doc file but if you open it using notepad OR any other text editor YOU will find that it is not valid .doc file) 这是我的示例代码(它生成.doc文件,但是如果您使用记事本或任何其他文本编辑器将其打开,则会发现它不是有效的.doc文件)

<?php
    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=file.doc");

    echo "<html>";
    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
    echo "<body>";
    echo "<b>My first document</b><br />";
    echo "This is test document and this is created by using by PHP headers (Sample data)";
    echo "</body>";
    echo "</html>";
?>

Use this in header you will get your output 在标题中使用它,您将获得输出

header("Content-Type: application/vnd.ms-excel");
 header('Content-Disposition: attachment; filename="MyMsDocFile.doc');

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

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