简体   繁体   English

如何在php页面上显示存储在数据库中的图像?

[英]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.

相关问题 如何在php页面上显示存储在数据库中的图像? - How do you display an image stored in a database on a php page? 如何使用MySQL数据库中存储的图像链接在PHP中显示图像? - How can I display image in PHP using image link stored in MySQL database? 如何显示存储在数据库 PHP 中的图像路径? (Laravel 兰花) - How do I display image path stored in database PHP? (Laravel Orchid) 如何以特殊日期显示存储在Mysql数据库中的图像而不是按ID(PHP) - How to display an image stored in Mysql database with special date not by id (php) 如何显示存储在数据库中的图像? - How to display an image that is stored in the database? 如何显示存储在数据库中的图像? - how to display an image stored in a database? 用php显示存储在数据库中的图像(tinyblob) - Display an image (tinyblob) stored in a database with php 使用PHP显示存储在mySQL数据库中的图像 - Display an image stored in mySQL database with PHP 考虑到我的图像链接存储在MySQL数据库中,如何通过php显示存储在文件夹中的图像 - How to display through php an image stored in a folder considering that my image's link is stored in MySQL database 我无法使用php从sql数据库显示图像。 如何显示它,如何一次显示更多图片? - I can' display an image from sql database with php. How is it possible to display it and how can I display more pictures at a time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM