简体   繁体   English

使用PHP从MySQL显示BLOB

[英]Display BLOB from mySQL with php

After I managed it to insert blobs into my db I'm trying to Display a BLOB from MySQL. 在我设法将blob插入我的数据库后,我试图从MySQL显示BLOB。

This is the getImage.php: 这是getImage.php:

<?php
  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "root");
  mysql_select_db("user_auth_tutorial");
  $sql = "SELECT image FROM testblob WHERE image_id='$id''";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);
  header("Content-type: image/jpeg");
  echo $row['image'];
?>

Here the HTML: 这是HTML:

<img src="getImage.php?id=1" width="200" height="200" />

This is the content of my db: 这是我的数据库的内容: 表testblob

Unfortunately Dev-Tools throw an internal server 500 Error. 不幸的是,Dev-Tools抛出内部服务器500错误。 Browser-Output: 浏览器输出: 屏幕截图

Can anybody tell me what I do wrong? 谁能告诉我我做错了什么?

Thank you so much! 非常感谢!

尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM