Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在symfony 2.7.3中显示mysql数据库中存储的blob图像_Php_Mysql_Symfony - Fatal编程技术网

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

Php 如何在symfony 2.7.3中显示mysql数据库中存储的blob图像,php,mysql,symfony,Php,Mysql,Symfony,我在我的网站上显示blob图像时遇到问题,我正在使用symfony 2.7.3。。。 我试图将blob数据编码到Base64中,我能够显示Base64的值,但当我将其嵌入其中时,什么也没有发生。下面是我的代码。 请问我做错了什么 控制器 看法 {%if徽章%} {%block-badge%} {%用于密钥,徽章中的徽章%} {%endfor%} {%endblock%} {%endif%} 这不是一个正确的答案,但我只是想建议您不要将大型数据存储在数据库中,而是将其作为字符串存储在服务器上的链接

我在我的网站上显示blob图像时遇到问题,我正在使用symfony 2.7.3。。。 我试图将blob数据编码到Base64中,我能够显示Base64的值,但当我将其嵌入其中时,什么也没有发生。下面是我的代码。 请问我做错了什么

控制器

看法

{%if徽章%}
{%block-badge%}
{%用于密钥,徽章中的徽章%}
{%endfor%}
{%endblock%}
{%endif%}

这不是一个正确的答案,但我只是想建议您不要将大型数据存储在数据库中,而是将其作为字符串存储在服务器上的链接。通过这种方式,您可以更轻松地访问数据,并且不会出现此类问题。希望这能有所帮助。你确定这是png图像吗?2.您确定图像数组包含正确的图像源吗?只需确保$badge->getImage()返回stream\u get\u contents()函数所需的内容,并且您拥有有效的base64\u编码图像内容。(我建议独立于你的应用程序进行检查-首先手动操作。)@Alex是的,我用png和jpg图像进行了测试,我还有图像数组echo的内容,它在base64中。我不知道该怎么办了这是我的get-image函数`/***get-image**@return-string*/公共函数getImage(){return$this->image;}`@Guillaume-Fache确实有用。。。我如何着手实施你建议的解决方案?你有这样的工作样本吗???!!这不是一个正确的答案,但我只是想建议您不要将大型数据存储在数据库中,而是将其作为字符串存储在服务器上的位置的链接。通过这种方式,您可以更轻松地访问数据,并且不会出现此类问题。希望这能有所帮助。你确定这是png图像吗?2.您确定图像数组包含正确的图像源吗?只需确保$badge->getImage()返回stream\u get\u contents()函数所需的内容,并且您拥有有效的base64\u编码图像内容。(我建议独立于你的应用程序进行检查-首先手动操作。)@Alex是的,我用png和jpg图像进行了测试,我还有图像数组echo的内容,它在base64中。我不知道该怎么办了这是我的get-image函数`/***get-image**@return-string*/公共函数getImage(){return$this->image;}`@Guillaume-Fache确实有用。。。我如何着手实施你建议的解决方案?你有这样的工作样本吗???!!
$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 %}