2013-10-07 44 views
0

我使用html_to_doc導出HTML以.doc格式這一切工作正常。 但我遇到的問題是,當我打開文檔並轉到另存爲默認文檔類型始終是的.htm/html的導出的Word文檔被保存爲HTM

我使用Linux,我想使用這個類,如果可以保持。這些都是在PHP的套頭:

@header("Cache-Control: ");// leave blank to avoid IE errors 
@header("Pragma: ");// leave blank to avoid IE errors 
@header("Content-type: application/octet-stream"); 
@header("Content-Disposition: attachment; filename=\"$this->docFile\""); 

和DOC頭(無樣式):

<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"> 

<head> 
<meta http-equiv=Content-Type content="text/html; charset=utf-8"> 
<meta name=ProgId content=Word.Document> 
<meta name=Generator content="Microsoft Word 9"> 
<meta name=Originator content="Microsoft Word 9"> 
<!--[if !mso]> 
<style> 
v\:* {behavior:url(#default#VML);} 
o\:* {behavior:url(#default#VML);} 
w\:* {behavior:url(#default#VML);} 
.shape {behavior:url(#default#VML);} 
</style> 
<![endif]--> 
<title>$this->title</title> 
<!--[if gte mso 9]><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><![endif]--> 
<!--[if gte mso 9]><xml> 
<o:shapedefaults v:ext="edit" spidmax="1032"> 
<o:colormenu v:ext="edit" strokecolor="none"/> 
</o:shapedefaults></xml><![endif]--><!--[if gte mso 9]><xml> 
<o:shapelayout v:ext="edit"> 
<o:idmap v:ext="edit" data="1"/> 
</o:shapelayout></xml><![endif]--> 
$this->htmlHead 
</head> 
+0

什麼在$這個 - > DOCFILE?這是否有一個.doc /擴展名爲.docx – RiggsFolly

+0

$這個 - > DOCFILE是剛剛由類 –

+0

這可能會幫助http://stackoverflow.com/questions/11487365/http-header產生的被下載的文件, -for-downloaded-microsoft-word-and-excel-files – RiggsFolly

回答

-1

嘗試使用這個作爲標題

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

,並確保文件名有一個.doc /或.docx擴展

+1

這將使用PHP的automagic擴展使它成爲一個真正的MS Word文檔文件?不! –

+0

就像我之前說過的:我可以正確下載文件,但當我嘗試再次保存文件時,它會變得很瘋狂...... –

+0

我知道你可以下載它。我正在假設如果你的系統確切地知道它已經下載了什麼類型的文件,它可能會默認保存一個word文檔而不是html文件。很明顯,單詞正在查看內容並查看它的HTML,並假設你想將它保存爲HTML。如果它被告知正確的格式作爲下載的一部分,它可能不需要作出暗示。 – RiggsFolly