无法显示MySQL表中的图像

时间:2015-03-09 08:52:38

标签: php mysql image

我正在搜索显示保存在MySQL表格中的图像的分辨率。我已经阅读了本网站几乎所有以前的问题。跟着他们,但没有运气。

我可以保存文件。在尝试显示时,它只显示二进制代码

我花了几天时间自己做,但在程序中找不到错误。

目的是使用3个不同的表格显示用户的姓名,姓氏,出生日期和图像,然后根据用户的需要进行更改。所有数据都显示得很好,并且也可以更改。但是不能显示图像.. !!

试图回应'第22行的图像用于测试,然后在第45行显示。两种方式只是二进制代码。任何帮助/建议将受到高度赞赏..

<?php
session_start();

include 'db_connect.php';

$user   = (isset($_POST['user']) && !empty($_POST['user']) ? $_POST['user'] :"");
$pass   = (isset($_POST['pass']) && !empty($_POST['pass']) ? $_POST['pass'] :"");   

$sql = mysqli_query($connect, "SELECT mli.cust_id, mm.fname, mm.lname, mm.cust_dob, mi.cust_img 
          FROM member_login_info mli 
          LEFT JOIN member_master mm   ON mli.cust_id = mm.cust_id
          LEFT JOIN member_img mi  ON mli.cust_id = mi.cust_id
          WHERE mli.profilename = '$user' AND mli.password = sha1('$pass') ");        

$result = mysqli_fetch_array($sql);

  $fname  = $result["fname"];
  $lname  = $result["lname"];
  $dob    = date("d/m/Y", strtotime($result["cust_dob"]));
  $_SESSION["cid"] = $result["cust_id"];
  $image = $result["cust_img"];
  echo "<img src='" .$result['cust_img']. "'>"
?>

<div id="edit_data"> 
 <fieldset style="width:30%">
    <legend>Edit information</legend> 

 <table border="0">
    <form name="edit" enctype="multipart/form-data" method="POST" action="test_edit1.php">
    <tr>        
    <td>First Name:</td>
    <td><input name="fname" type="text" id="fname" value="<?php echo $fname; ?>" > </td> 
    </tr>   
    <tr> 
    <td>Last Name:</td> 
    <td><input name="lname" type="text" id="lname" value="<?php echo $lname; ?>"> </td> 
    </tr>   
    <tr> 
    <td>Date of Birth:</td><td> 
    <input name="dob" type="text" id="dob" value="<?php echo $dob; ?>"> </td>
    <input name="cid" value="<?php echo $cid; ?>" type="hidden" />
    </tr>   
    <tr> 
    <td>Photo:</td> <td> <?php echo "<img src='".$result['cust_img']."'/>" ?> </td>
    </tr>

    <tr> 
    <td>Upload your profile picture:</td><td> <input name="image" type="file"> </td>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    </tr> 

    <tr> 
    <td><input id="exit" type="submit" name="exit" value="Exit" onclick="window.location.href='display.html'"></td>
    <td><input id="edit" type="submit" name="edit" value="Save"></td>  
    </tr> 
    </form> 
 </table>

1 个答案:

答案 0 :(得分:1)

我假设您没有存储该图像的路径,但是图像内容本身并且它是jpg(您可以更改为png或您拥有的任何类型)。如果是这样,请使用src的数据URI语法:

$src = "data:image/jpg;base64,".base64_encode($result['cust_img']);
echo "<img src='$src'>";
相关问题