2

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). 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. Anybody please help me to create a REAL .doc file

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)

<?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>";
?>
3
  • livedocx.com supports .doc, .docx, .rtf and .pdf generation Commented Dec 7, 2013 at 23:26
  • can I do it using PHP (custom PHP) not livedocx.com as I've checked that already. Commented Dec 7, 2013 at 23:34
  • 2
    I'm not aware of any PHP library that creates BIFF format .doc files: I know a bit about Word Processing formats, and PHPWord only writes OfficeOpenXML .docx, OASIS .odt and Rich Text .rtf files Commented Dec 7, 2013 at 23:36

1 Answer 1

1

Use this in header you will get your output

header("Content-Type: application/vnd.ms-excel");
 header('Content-Disposition: attachment; filename="MyMsDocFile.doc');
Sign up to request clarification or add additional context in comments.

1 Comment

any more explaination

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.