无法显示MySQL表中的图像 [英] Unable to display image from MySQL table

查看:79
本文介绍了无法显示MySQL表中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm searching for a resolution for displaying image which is saved in MySQL table. I have read almost all the previous questions in this site. Have followed them, but no luck.

我能够保存所有文件.尝试显示时,它仅显示二进制代码.

花了几天时间自己做,但是找不到程序中的错误.

Have spend several days to do it myself, but couldn't find the mistake in program.

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

The aim is to display the users Name, last name, date of birth and image using 3 different tables, and then change them if the user wants. All the data are displayed fine and able to change as well. But cant display image..!!

尝试在第22行中回显"图像以进行测试,然后在第45行中显示该图像.两种方式都只是二进制代码.任何帮助/建议将不胜感激..

Have tried to 'echo' the image in line 22 for testing and then in line 45 where is should display. Both ways its just the binary codes. Any help/suggestions will be highly appreciated..

<?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>

推荐答案

我假定您不存储该图像的路径,但是图像内容本身是jpg(可以更改为png或任何类型)你在那里).如果是这样,请对src使用数据URI语法:

I assume that you don't store a path to that image, but the image content itself and that it is jpg (you can change to png or whatever type you have there). If so, use data URI syntax for src:

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

这篇关于无法显示MySQL表中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆