【发布时间】:2016-04-15 20:28:14
【问题描述】:
我正在尝试使用 PHP 和 twig 显示来自数据库的图像。我很难做到这一点。在我的index.twig 中有这行代码:<a><img class="images" src="showImg.php?id={{ text.getImage() }}" /></a>。
{{ text.getImage() }} 来自for-loop,showImg.php 将根据给定的ID 参数执行选择图像的查询。
在我的showImg.php:
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
$sql = "SELECT filename, mime, code FROM Img_col WHERE id = :id";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
while($row = $stmt->fetchObject('Image')) {
$this->result[] = $row;
}
Header("Content-type: $img->getMime()");
Header("Content-Disposition: filename=\"$img->getFileName()\"");
$img->hentCode();
}
我的第一个问题是 IDE 在$stmt = $this->db->prepare($sql); 行中停止,我的第二个问题是如何将图像(code)发送到index.twig。
任何可以帮助我的想法或提示都非常感谢。我愿意接受任何建议
【问题讨论】: