php读取mysql图片数据类型_我如何显示图像存储为MySQL中的blob数据类型与PHP?

bd96500e110b49cbb3cd949968f18be7.png

How do i display an image stored in mySQL database as BLOB ?

What it tried so far:

1. Created a new php function/file to get picture (getpicture.php).

2. In the html, I have the following code:

getpicture.php?id=2

/*below is the getpicture.php*/

@ $db = new MySQLi('localhost','root','','myDatabase');

if(mysqli_connect_errno()) {

echo 'Connection to database failed:'.mysqli_connect_error();

exit();

}

if(isset($_GET['People_Id'])) {

$id = mysqli_real_escape_string($_GET['People_Id']);

$query = mysqli_query("SELECT * FROM 'people' WHERE 'People_Id' = '$id'");

while($row = mysqli_fetch_assoc($query)) {

$imageData =$row['image'];

}

header("content-type: image/jpeg");

echo $imageData;

echo $id;

}

else {

echo "Error!";

echo $id;

}

?>

What's wrong with the codes ? Please help!

解决方案

I answered my own question, it's working now..

Below is the getpicture.php:

$db = new MySQLi('localhost', '', '', 'mydatabase');

if ($db->connect_errno) {

echo 'Connection to database failed: '. $db->connect_error;

exit();

}

if (isset($_GET['id'])) {

$id = $db->real_escape_string($_GET['id']);

$query = "SELECT `Picture` FROM member WHERE `Id` = '$id'";

$result = $db->query($query);

while($row = mysqli_fetch_array($result)) {

$imageData = $row['Picture'];

header("Content-type:image/jpeg");

echo $imageData;

}

}

?>

The php script which retrieve the getpicture.php above looks like this:

echo 'getpicture.php?id='%20.%20htmlspecialchars(%24_GET%5B';

Thaank you all for the help

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值