doufang7385
2016-03-23 12:01
浏览 260
已采纳

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Ñ.....

图片转代码服务由CSDN问答提供 功能建议

我正在显示我的BLOB图像并且它正在工作。

 &lt; img src =“&lt;?php echo'data:image; base64,'。$ row_img ['image'];?&gt;”  alt“”/&gt; 
   
 
 

但是当我尝试复制图片链接并在网址中打开它时,它会显示加密代码,如下所示: ÿØÿà�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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongneng5383 2016-03-23 12:05
    已采纳

    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'];
    
    打赏 评论
  • dongshengyin0147 2016-03-23 12:04

    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.

    打赏 评论
  • doupan6648 2016-03-23 12:07

    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"" />
    
    打赏 评论

相关推荐 更多相似问题