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

时间:2022-09-03 21:21:40

I have a php script that generates a word document by creating it in HTML and outputting it to .doc when attaching static images from my website, the images load fine in Microsoft Word 03 and 2010. However when attempting to use a URL to generate an image (by parsing it a parameter) the image doesn't seem to load.

我有一个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);

Heres what I'm trying to do, I have a URL (website.com/signature.php?form=XXXX) where XXX is the form ID. The signature.php takes in the ID nunmber, locates the JSON stored on the server and generates an image from the JSON file, using this jquery plugin http://thomasjbradley.ca/lab/signature-to-image/

继承人我正在尝试做什么,我有一个URL(website.com/signature.php?form=XXXX),其中XXX是表单ID。 signature.php接收ID nunmber,找到存储在服务器上的JSON并使用此jquery插件生成JSON文件中的图像http://thomasjbradley.ca/lab/signature-to-image/

The signature/image converts fine and I see it when I test it against some examples, however when opening up the document in word, it doesn't show.

签名/图像转换得很好,我在一些例子中测试它时看到它,但是当用文字打开文档时,它没有显示。

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

That's what I have for my HTML.

这就是我对HTML的看法。

EDIT:

编辑:

In my signature.php I have the following:

在我的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 个解决方案

#1


0  

I'd imagine it's looking at the headers, and not seeing what it wants.

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

Within the signature.php script, directly before outputting the image, try adding:

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

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

... Replacing jpeg with whatever format the image is being output as.

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

Let me know if that works, and we can take it from there.

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

#1


0  

I'd imagine it's looking at the headers, and not seeing what it wants.

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

Within the signature.php script, directly before outputting the image, try adding:

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

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

... Replacing jpeg with whatever format the image is being output as.

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

Let me know if that works, and we can take it from there.

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