1

I have created HTML to Doc using php and header. It creates proper doc file what I want but when I download that doc file and click on SAVE AS its default type as webpage( .html).

Here is my code I am using to create doc file.

header('Content-Description: File Transfer');
header("Content-type: application/msword;charset=iso-8859-8");
header('Content-Disposition: attachment;filename=IEP-Annual-Goals.doc');
header("Pragma: no-cache");
header("Expires: 0");

$html='<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40"> 
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-8" />
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">

<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>90</w:Zoom>
<w:Save>.doc</w:Save>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>';
// and main html block

//Then simply echo html to directly download doc file.
echo $html;    

When I open doc file and save as, Its default type is web document(.html) but I need it as document(.doc) file.

1 Answers1

0

Maybe, your doing this all wrong there is already phpword

https://github.com/PHPOffice/PHPWord

Which'll create doc files for you.

Richard Housham
  • 1,525
  • 2
  • 15
  • 31
  • I already tried phpword but for that I need to recreate entire structure of file because in phpword my existing html not showing properly. – Bhavesh Malaviya Mar 29 '18 at 12:58
  • It has a phpword has a html to doc function. https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_26_Html.php In the past I also used the phpword replace function so have 'replace' areas that you can replace with your variables. That might be good enough for you. – Richard Housham Mar 29 '18 at 13:07