php blob mysql 图片,正确的标题php mysql blob显示图像

i am attempting to display an image from mysql blob (i know its not best practice) in my PHP page which i will then bring into my iOS app.

I'm having trouble setting the page header which i believe needs to be set as an image.

So, this shows the image but I do not believe the page header is correct:

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

echo '';

However, this does not show my image:

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

echo '';

What am I missing? I believe the image should show when the header is set to image/png but i'm getting an error that it cannot be displayed because of errors.

Thank you!

解决方案header("Content-type: image/png");

This tells your browser that you're about to pass it raw binary data that is a PNG file. So anything output after that would have to be a binary PNG. You can't then place HTML and expect that to work

echo '';

This works because you're base64 encoding your image (translates binary into text), outputting that to the browser and then telling your browser to interpret it as base64.

If you want to output the raw binary data you have to rearrange the order. So here's your HTML

image.php

Now you'll note the src points to a PHP file. That's because we're going to have that PHP file return an image. Here's what image.php would look like

//Your query here

$row = mysqli_fetch_assoc($result);

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

echo $row['image1'];

This works because the browser will call the PHP file, expecting an image. The header tells the browser that this is a PNG file and you can now dump your binary PNG data.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值