dqs66973 2017-03-11 09:35
浏览 53
已采纳

从mysql中检索后图像没有显示

Below is code for searching and displaying images based on username:

<?php
$s=0;
if(isset($_POST['submit'])){
    $servername = "localhost";
    $username = "root";
    $password = "123456";
    $dbname = "photost";
    $conn=mysqli_connect($servername, $username, $password, $dbname);
    $user_id=$_POST['user_id'];
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }
    $query="SELECT `id`,`image`, `file_name` FROM `images` WHERE `u_id`='$user_id'";
    $result =mysqli_query($conn, $query);
    $s=1;
}
?>
<body>
    <div style="width:100%;height:10%;">
    </div>
<div align=center>
<form action="" method="POST" enctype="multipart/form-data">
    <table style="width:40%">
    <tr>
    <th align="right">User Id:</th>
    <th> <input type='text' name='user_id'></th>
        <th align="left"> <input type="submit" name="submit"    ></th>
  </tr>
</table>
</form>
</div>
<div style="width:80%;height:1000px;margin:auto;">
<?php
if($s==1){
    if (mysqli_num_rows($result) > 0) {
        $c=1;
        while($row = mysqli_fetch_assoc($result)) {
            echo "<div style='width:24%;float:left;margin-left:2px;margin-top:5px;'>";
            echo "<img style='height:250px;width:80%;margin:auto;' src=getImage.php?id='$row[id]' /><br>";
            echo $row["id"] .". ". $row["file_name"]."<br></div>";
            }
            }
}
 ?>
</div>


</body>

Below code is for fetching image from db based on image id:

<?php
if(isset($_GET['id'])){
  $id = $_GET['id'];
  $servername = "localhost";
  $username = "root";
  $password = "123456";
  $dbname = "photost";
  $conn=mysqli_connect($servername, $username, $password, $dbname);
  if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
  }
  header("content-type: image/jpeg");
  $query="SELECT `image` FROM `images` WHERE `id`='$id'";
  $result =mysqli_query($conn, $query);
  $row = mysql_fetch_assoc($result);

  echo $row['image'];
}

?>

Tried Many Solution Nothing Worked.I'm able to display one image using header("content-type: image/jpeg") in main page.but while using it in getimage.php only image icon is displayed.as shown below:

Screenshot (Images where userid=1)

Plz Suggest me something.....

  • 写回答

2条回答 默认 最新

  • dongshao1156 2017-03-11 12:28
    关注

    Make the following change in your first code:

    echo "<img style='height:250px;width:80%;margin:auto;' src='data:image/jpeg;base64,".base64_encode( $row['image'] )."'/><br>";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应