我需要我的PHP页面来显示我的mysql数据库中的BLOB图像 [英] I need my PHP page to show my BLOB image from mysql database

查看:165
本文介绍了我需要我的PHP页面来显示我的mysql数据库中的BLOB图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的最后一个问题是关于如何从搜索中显示我的techID:

So my last question was on how to have my techID shown from a search :

我正在尝试使用我的详细信息页面引用我的服务器中通过techID链接的两个单独部分

我的新问题仍在此页面上。我也添加了一个回声图像。但是我在使用 Blob 时遇到问题并让它显示我的图像而不是二进制JPEG数据。
我一直试图找到另一个这样的例子,但找不到任何修正我的错误。

My new question is still on this page. I have added in an echo image as well. but am having trouble using Blob and having it display my image and not binary JPEG data. I've been trying to find another instance of this but cannot find any that fix my error.

//Header ('Content-type: image/jpeg')
echo "<dt><strong>Technician Image:</strong></dt><dd>" . '<img src='.$row2['image'].' width="290" height="290">' . "</dd>";

$query_Recordset2 = "SELECT * FROM technician WHERE techID=" . $row1["techID"] ;
$Rs2 = mysql_query($query_Recordset2) or die(mysql_error());

到目前为止,我在上一个问题中所做的唯一更改(显然包括我的修正)鉴于有效)。

Are the only changes I have put in so far from my last question (obviously including the fix I was given that worked).

我不明白的地方和方法'Content-type:image / jpeg'让我的页面识别出链接的图像是MIME TYPE image / jpeg

What I do not understand is where and how to put 'Content-type: image/jpeg' to have my page recognize the image being linked is it's MIME TYPE image/jpeg.

我是什么在我的页面上看到的是这个

What I am seeing on my page is this


技术员图片:$ b $b E j i`= 7f $D ○bCkkcR ^ M; N〜0安培;米)JRE)JDRE)JDRE) JDR E)JDR E)JDR E)JDSjR ) + N .R,u i n9, QX~
{( ̮ : 2 12 aV7 6 { LP[ W گ R $ + $ b $b LMc'hM 5 o PA | .8 E ģ Rn$ b $b 1 [ { 3> RYX; Ǖ u z ' vf N葟$ b $b z Q k 3 O ܨ ٔ ٔ ?S ,N [{+D
; ' $ $ & iJR )JR )JR )JR )JR )JR )JR )JR )JR )JR )JR )JR )
width =290 height =290>

Technician Image: �E��j��i`=7f$D��o"�������b���Ckkc��R��^M�;n~��0&m)J��R��E)JDR��E)JDR��E)JDR��E)JDR��E)JDR��E)JDSjR��)���+��N��.R,u����i��n9,���QX~ ����{(����̮�:���2�12��"��aV7�6���{���LP[�W�����گ� R$+� ��LMc'hM�5�o�PA����|���ګ���.8��E��ģ��Rn ��1�[��{��3>�rY��X�ۜ;�Ǖ����u���z��'�vf�N葟 ��z�Q�����k��3���O��ܨ�ۀ�?S���,N� �����[{+D� �;�'�$�$�&�iJR��)JR��)JR��)JR��)JR��)JR��)JR��)JR��)JR��)JR��)JR��)JR��)�� width="290" height="290">

显然我删除了一个中间块,所以它不是很大。有一个小的破碎的图像框出现在前面,当我右键单击并选择在新窗口中打开图像时,它放入的URL只是内容类型:或者我得到一个带有URL的禁止访问页面 http:// localhost / Sim5Server / Pages /%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD %EF%BF%BD%10JFIF%EF%BF%BD%01%02%EF%BF%BD%EF%BF%BDD%EF%BF%BDD%EF%BF%BD%EF%BF%BD%EF %BF%BD%EF%BF%BD%EF%BF%BDC%EF%BF%BD

Obviously I have deleted a middle chunk so it's not massive. there is a little "Broken image" box that appears infront and when I right click and choose "Open image in new window" the URL it puts in is simply Content-type: or I get a forbidden access page with the url http:// localhost/Sim5Server/Pages/%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%10JFIF%EF%BF%BD%01%02%EF%BF%BD%EF%BF%BDd%EF%BF%BDd%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDC%EF%BF%BD

我已放入空格那个网址,因为它不是互联网的链接。

I have put a space in that url since it is not a link for the internet.

我只使用普通的BLOB类型,因为我只需要一个小于64Kb的小图像

I have only used normal BLOB type as I just need it as a small less than 64Kb image

推荐答案

在目前的情况下,您有两个前期选项。

In your current case, you have two upfront options.

第一个,如果你有这么多的图像我不建议使用内联base64编码。这完成了:

The first, and the one I don't recommend if you have numerous images like this, is to use inline base64 encoding. This is done with:

<img src="data:image/jpeg;base64,<?php echo base64_encode($image); ?>" />

复制/粘贴版本,使用现有代码:

A copy/paste version, using your existing code:

echo '<dt><strong>Technician Image:</strong></dt><dd>'
     . '<img src="data:image/jpeg;base64,' . base64_encode($row2['image']) . '" width="290" height="290">'
     . '</dd>';

第二种方法是创建一个图像PHP文件,该文件获取图像的ID数据库作为查询字符串参数并输出图像。所以,你的HTML看起来像:

The second method is to create an "image" PHP file that takes the ID of the image in the database as a query-string parameter and outputs the image. So, your HTML would look something like:

<img src="image.php?id=<?php echo $image_id; ?>" />

您的PHP页面看起来类似于:

And your PHP page would look something similar to:

<?php
$id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? intval($_GET['id']) : 0;
$image = getImageFromDatabase($id); // your code to fetch the image

header('Content-Type: image/jpeg');
echo $image;
?>

这篇关于我需要我的PHP页面来显示我的mysql数据库中的BLOB图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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