0
Ich habe einige Bilder in einer SQL Server-Datenbank in einer BLOB-Spalte.Silex + Zweig + SQL Server: Rendern von Bildern
Ich muss sie bekommen und auf die HTML-Seite zeigen.
Aber im Ergebnis auf der HTML-Seite habe ich die lange Zeichenfolge in src
Attribut anstelle der Bilder.
Silex Code:
<!-- 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;
}
Zweig Datei:
<!-- 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-Markup:
<!-- 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>
Was mit ihm los?