Display image stored in BLOB database in symfony

前端 未结 4 1007
温柔的废话
温柔的废话 2021-01-21 10:19

I load my image (blob data ) in my GETer Entity When I just return ($this->foto) in my GETer I see :Resource id #284 on the screen When I change my GETer like this : return stre

4条回答
  •  星月不相逢
    2021-01-21 10:53

    You are using instead of

    A quick solution is to encode your image in base64 and embed it.

    Controller

    $images = array();
    foreach ($entities as $key => $entity) {
      $images[$key] = base64_encode(stream_get_contents($entity->getFoto()));
    }
    
    // ...
    
    return $this->render('CustomCMSBundle:Producten:index.html.twig', array(
        'entities' => $entities,
        'images' => $images,
    ));
    

    View

    {% for key, entity in entities %}
      {# ... #}
      Embedded Image
      {# ... #}
    {% endfor %}
    

提交回复
热议问题