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

查看:31
本文介绍了我需要我的 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

技术员图片:E j i`=7f$D o" b Ckkc R ^M ;n~ 0&m)J RE)JDR E)JDR E)JDR E)JDR E)JDR E)JDSjR ) + N .R,ui n9, QX~{( ̮ : 2 12 " aV7 6 { LP[ W گ R$+LMc'hM 5 o PA | ګ .8 E ģ Rn1 [ { 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">

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 只是 Content-type: 或者我被禁止访问带有网址的页面 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天全站免登陆