0
SQL ServerデータベースにBLOB列の画像があります。Silex + Twig + SQL Server:画像のレンダリング
私はそれらを取得し、HTMLページに表示する必要があります。
しかし、HTMLページの結果では、写真の代わりにsrc
という属性の長い文字列があります。
サイレックスコード:
<!-- language-all: php -->
$pict->get('/show_pic/{id}', function ($id) use ($app) {
//Request of photos
$photos=getPhotoByID($id, $app);
return $app['twig']->render('test/template_show_pictures.html.twig', array('photos'=>$photos));
})->bind('show_pic');
function getPhotoByID($ID, $app)
{
$sql = "<some SQL here>";
$statement = $app['dbs']['mssql']->prepare($sql);
$statement->bindValue(1, $ID, "text");
$statement->execute();
$photo = $statement->fetchAll();
if (empty($photo)) {
return "We don't have a photo with id=".$ID;
}
return $photo;
}
小枝ファイル:
<!-- language: twig -->
{% extends 'test/test_base.html.twig' %}
{% block title %}Pictures from DB{% endblock %}
{% block content %}
{% for im in photos %}
<img alt="Embedded Image" src="data:image/jpeg;base64,{{ im['Foto'] }}" />
{% endfor %}
{% endblock %}
HTMLマークアップ:
<!-- language: lang-html -->
<!DOCTYPE html>
<html>
<head>
<title>Pictures from DB</title>
<link rel="stylesheet" href="/css/print.css">
</head>
<body>
<div class="page">
<img alt="Embedded Image" src="data:image/jpeg;base64,���JFIF...too many symbols here" />
</div>
</body>
</html>
それの何が問題になっているのですか?