PHP HTML Word Doc不显示通过URL生成的图像

时间:2013-03-20 23:57:12

标签: php html ms-office doc

我有一个php脚本,通过在HTML中创建word文档并在从我的网站附加静态图像时将其输出到.doc,这些图像在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 nunmber,找到存储在服务器上的JSON,并使用此jquery插件http://thomasjbradley.ca/lab/signature-to-image/

从JSON文件生成图像

签名/图片转换得很好,我在针对某些示例测试时看到了它,但是当用文字打开文档时,它没有显示。

<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);
  }

1 个答案:

答案 0 :(得分:0)

我想它正在看标题,而不是看到它想要的东西。

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

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

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

如果有效,请告诉我,我们可以从那里开始。