PHP BLOB图像显示在网站上但无法在新选项卡中打开它
I'm displaying my BLOB image like this and it is working.
<img src="<?php echo 'data:image;base64,'.$row_img['image']; ?>" alt"" />
But when i try to copy image link and open it in url, it show me encrypted code like this :
ÿØÿà�JFIF���
��ÿÛ�C�ÿÛ�CÿÀ�6î"�ÿÄ�����������
ÿÄ�µ���}�!1AQa"q2‘¡#B±ÁRÑð$3br‚
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ��������
ÿÄ�µ��w�!1AQaq"2B‘¡±Á #3RðbrÑ.....
我正在显示我的BLOB图像并且它正在工作。 p>
&lt; img src =“&lt;?php echo'data:image; base64,'。$ row_img ['image'];?&gt;” alt“”/&gt;
code> pre>
但是当我尝试复制图片链接并在网址中打开它时,它会显示加密代码,如下所示:
ÿØÿà�JFIF� 代码>ÿÛCÿÛCÿÀ6î “YA,点击
ÿÄμ}!1AQa” Q2 '¡#B±ÁRÑð$ 3br,
%&amp;'()* 456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ“...†‡‰'”“• - 〜™¢¢¤¥|§|²²³μμ· ¸¹ºÂÃ¼ÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÿ����������������\ÿÿÿ����1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A
That's the data url displayed as text, the browser doesn't know its a jpeg.
Add the correct mime type to the url and it should work
echo 'data:image/jpeg;base64,'.$row_img['image'];
Your content type for your data is wrong. image
is not valid. It should be image/png
or image/jpeg
or something similar depending on the type of image.
From what you posted, it looks like your image is a JPEG.
Because the browser has no way to know the mime type with inline image. Open them with img tag is Ok because you tell the browser it's an image. But without context in a new tab it s just a random string
EDIT : use a full correct mime
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" alt"" />