doupeng8494 2018-09-27 14:20
浏览 67

使用PHP将图像插入docx文件的最简单方法

I am trying to set up an export button on a website that will export some information from a database and put it into a .doc file. I'm currently doing this with:

$filename = "File.doc"; 

header('Content-Type: application/octet-stream');    
header("Content-Disposition: attachment; filename=$filename");

echo "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\"><body><img src='the_img.png' width='250px'><br><br><b style='font-size: 40px;'><u><center>Header</center></u></b><br><br><ol>";

$fileData = "SELECT `Songs` FROM `table`;";
$info = $con->query($fileData);
while ($the_row = $info->fetch_assoc()) {
    $content = $the_row["column"];
}

$arr = explode("|", $content);

for($i = 0; $i < count($arr); $i++){
    echo "<li>" . $arr[$i] . "</li>";
}

echo "</ol></body></html>";

mysqli_close($con);

exit;

When it exports the .doc file it successfully opens in Microsoft Word, however the image appears to be broken until you enter edit mode. Once you're in edit mode the image has no specific size set. Any suggestions?

  • 写回答

1条回答 默认 最新

  • dsvs50005 2018-11-21 10:09
    关注

    The problem is on this line I think

    echo "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows- 
    1252\"><body><img src='the_img.png' width='250px'><br><br><b style='font-size: 40px;'> 
    <u><center>Header</center></u></b><br><br><ol>";
    

    You have to change the name of the image to be without space and add "style" before "width" like this

    <img src="theimg.png" style="width:250px"/>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)