【问题标题】:PHP HTML Word Doc not showing image generated via URLPHP HTML Word Doc不显示通过URL生成的图像
【发布时间】:2013-03-20 23:57:11
【问题描述】:

我有一个 php 脚本,它通过在 HTML 中创建并输出到 .doc 来生成一个 word 文档,当从我的网站附加静态图像时,图像在 Microsoft Word 03 和 2010 中加载良好。但是当尝试使用生成图像的 URL(通过解析参数)图像似乎没有加载。

header('Content-type: application/ms-word');
header('Content-Disposition: attachement;filename="report.doc"');
header('Content-Transfer-Encoding: binary');
print($output);

这就是我想要做的,我有一个 URL (website.com/signature.php?form=XXXX),其中XXX 是表单 ID。 signature.php 接受 ID 号,定位存储在服务器上的 JSON 并从 JSON 文件生成图像,使用这个 jquery 插件http://thomasjbradley.ca/lab/signature-to-image/

签名/图像转换得很好,当我针对一些示例对其进行测试时,我看到了它,但是当用 word 打开文档时,它没有显示。

<img style="display: block;" alt = "" width="200" height="74" src = "http://myWebsite.net/signature.php?form=' . $results[$i]['id'] . '" />

这就是我的 HTML 所拥有的。

编辑:

在我的 signature.php 中,我有以下内容:

  require("DB/DBConnection.php");
  require("signature-to-image.php");

  $formID = $_REQUEST['form'];
  $dbh = DBConnection::connection();
  $sql = "SELECT signature FROM forms where id = ?";
  $stmt = $dbh->prepare($sql); 
  $stmt->bindValue(1, $formID, PDO::PARAM_STR);
  $stmt->execute();
  $result = $stmt->fetch();
  if ($result != null) {
    $img = sigJsonToImage($result['signature']);
    header('Content-Type: image/jpeg');
    imagejpeg($img);
    imagedestroy($img);
  }

【问题讨论】:

  • 那是您正在编写的实际 html 吗?还是编写 html 的 PHP 的一部分?
  • @MarkBaker 它是编写 html 的 php 的一部分。 $output .= &lt;img style="display: block;" alt = "" width="200" height="74" src = "http://myWebsite.net/signature.php?form=' . $results[$i]['id'] . '" /&gt; 是我所拥有的,还有一大堆我没有添加到 OP 中的其他文本

标签: php html ms-office doc


【解决方案1】:

我想它正在查看标题,而不是看到它想要的内容。

signature.php 脚本中,直接在输出图像之前,尝试添加:

header('Content-Type: image/jpeg');

...用输出图像的任何格式替换 jpeg。

让我知道这是否有效,我们可以从那里得到它。

【讨论】:

  • 这是一个 jpeg 文件,但是我在每个页面的标题中使用了静态硬编码图像(一个徽标),在 Word 中显示得很好
猜你喜欢
  • 1970-01-01
  • 2015-10-09
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多