dongliang1873 2015-05-24 23:00
浏览 56

从MySQL服务器解码Base64映像

I am storing my image as BLOB in an online MySQL database by encoding the image using Base64. I don't have a problem with saving. But I can't retrieve the images from the server. They appear to be broken. I believe this is happening because it's not being decoded.

I tried manually uploading a couple of photos to the server, and they are retrieved properly since they are not encoded. This is the code I'm using to retrieve the image. Can someone please tell me how to decode the image?

<?php
$db = mysql_connect("localhost","un","pw") or die(mysql_error()); 
mysql_select_db("datab",$db) or die(mysql_error()); 
$userId = $_GET['eid']; 
$query = "SELECT image FROM event WHERE eid='$userId'"; 
$result = mysql_query($query) or die(mysql_error()); 
$photo = mysql_fetch_array($result); 
header('Content-Type:image/png;base64'); 
echo $photo['image']; 
?>
  • 写回答

2条回答 默认 最新

  • dsfbnhc4373 2015-05-24 23:48
    关注

    First, please note that mysql syntax is outdated and totally deprecated ! Please use mysqli or PDO instead !

    Then, following your code, you just have to call you image in your html file, like that :

    <img src="data:image/png;base64, <?php echo $photo['image']; ?>">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起