[英]How can I display an image stored in a database on a php page?
I couldn't manage to show retrieved blob image file as image on my php page. 我无法在PHP页面上将检索到的Blob图像文件显示为图像。 The code part that shows the retrieved data from the database is as follows:
显示从数据库中检索到的数据的代码部分如下:
echo '<h4>'.$yaz["Header"].'</h4><br>'.$yaz["Picture"].'<p class="text">'.$yaz["Description"].'</p><br>';
when I write this code, I get Header and Description and any problem does not occur. 当我编写此代码时,我得到Header和Description,并且不会发生任何问题。 But the picture comes as
但是图片来了
����JFIFHH��:>ExifMM*����(2�;���i؈%PdCanonCanon EOS 500DHH2012:09:05 10:23:46
How can I display my picture on the php page? 如何在php页面上显示图片?
That's simple. 很简单
Just don't store an image in database in a blob field. 只是不要在Blob字段中将图像存储在数据库中。 Instead, store the image itself on a filesystem, while in database store only name of the file.
而是将映像本身存储在文件系统中,而在数据库中仅存储文件名。 this way your code would work.
这样,您的代码就可以工作。
echo '<h4>'.$yaz["Header"].'</h4><br><img src='.$yaz["Picture"].'><p class="text">'.$yaz["Description"].'</p><br>';
Don't store the image in the database. 不要将图像存储在数据库中。 store it in your file system.
将其存储在文件系统中。 store name and location of the file in the database.
在数据库中存储文件的名称和位置。 Because
因为
1.If database is corrupted, no way to retrieve. 1.如果数据库损坏,则无法检索。
2.Retrieving image files from db is slow when compared to other option. 2.与其他选项相比,从数据库检索图像文件的速度较慢。
Try like this: 尝试这样:
$image = $row['image'];
$image_type= $row['image_type'];
$size = $row['image_size'];
$ext = explode('/', $image_type);
$name = $id . '.' . $ext[1];
header("Content-type: $image_type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
print $image;
exit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.