【发布时间】: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 .= <img style="display: block;" alt = "" width="200" height="74" src = "http://myWebsite.net/signature.php?form=' . $results[$i]['id'] . '" />是我所拥有的,还有一大堆我没有添加到 OP 中的其他文本