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

问题描述

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

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

我的新问题仍在此页面上。我也添加了一个回声图像。但是我在使用 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

显然我删除了一个中间块,所以它不是很大。有一个小的破碎的图像框出现在前面,当我右键单击并选择在新窗口中打开图像时,它放入的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:

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

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图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 01:58