【发布时间】:2012-06-04 12:10:49
【问题描述】:
我正在用 PHP 编写一个脚本,该脚本使用 file_get_contents 获取一个 xml 文档,我用 str_replace 替换了一些字符,然后我用 fwrite 在 Word 文档中写入了这个文件。
示例:
$myContent = file_get_contents("../ressources/fichiers/modeles_conventions/modele_convention.xml");
$lettre = str_replace("@NOMENT@",utf8_encode($data['nomentreprise']),$lettre);
$newFileHandler = fopen("../ressources/fichiers/conventions/lettre_convention_1.doc","a");
fwrite($newFileHandler,$lettre);
fclose($newFileHandler);
在本地主机上它正在工作,但在服务器上问题是:
我的 xml 文件包含图像,但我的最终 .doc 文档没有检索到这些图像。
我不明白为什么我的图片没有被检索到。
好吧,我没有找到解决问题的方法。
我得到了我的 xml 文件(实际上是一个带有 .xml 扩展名的 .doc 文件)
$myContent = file_get_contents("../ressources/fichiers/modeles_conventions/modele_convention.xml");
我替换了一些东西
$myContent = str_replace("@NOM_ENTREPRISE@",stripslashes($data['nomentreprise']),$myContent);
$myContent = str_replace("@STATUT_ENTREPRISE@",stripslashes($data['juridique']),$myContent);
我保存我的文档
//On génère la convention
$newFileHandler = fopen("../ressources/fichiers/conventions/convention_".$data2['nomeleve']."_".$data2['prenomeleve']."_".$data3['idstage'].".doc","ab");
fwrite($newFileHandler,$myContent);
fclose($newFileHandler);
xml 文档包含图像,在 localhost 中它检索图像但不在服务器上。
xml代码示例:
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
<wx:font wx:val="Arial"/>
</w:rPr>
<w:pict>
<v:shape id="_x0000_i1028" type="#_x0000_t75" style="width:48.75pt;height:24pt">
<v:imagedata src="wordml://06000003.emz" o:title=""/>
</v:shape>
</w:pict>
</w:r>
</w:p>
【问题讨论】:
-
除非你启用了 PHP 的 automagically_convert_files 扩展,否则你会意识到你并没有生成一个真正的 .doc 文件,只是告诉 PHP 对你的客户端浏览器撒谎并假装这个 XML 是一个 Word 文档跨度>
-
我认为我的问题是相反的,它的word文档只是保存为.xml文件。
标签: php image file-get-contents