如何在symfony 2.7.3中显示存储在mysql数据库中的blob图像

时间:2015-09-22 11:32:29

标签: php mysql symfony

我无法在我的网站上显示blob图像,使用的是symfony 2.7.3 ... 我试图在base 64中对blob数据进行编码,我能够显示基数为64的值,但是当我将其嵌入时没有任何反应发生在下面是我的代码。 请问做错了什么?

  

控制器

$badges = $this->getDoctrine() 
     ->getRepository('AppBundle:News')->findAll();
    $images = array();
    foreach ($badges as $key  => $badge) {
         $images[$key] = base64_encode(stream_get_contents($badge->getImage()));

    }

    return $this->render('default/index.html.twig', array(
            'badges' => $badges,
         'images' => $images,

    ));
}
  

视图

    {% if badges %}
    {% block badge %}
       {% for key,badge in badges %}

             <div style = "margin:4px;height:100px" class="thumbnail">

                 <div class="pull-left">
                           <a href=""><img alt="embeded image"src="data:image/png;base64,{{ images[key] }}" />
                    </div>
                     <div style="width:auto" class = "pull-right" >
                                {{ badge.title }}
                     </div>
                        </a>
             </div>
        {% endfor %}
    {% endblock %}
{% endif %}

0 个答案:

没有答案