简体   繁体   English

PHP图像从数据库显示

[英]Php images display from database

i created a form which store clients passports in my database. 我创建了一个将客户护照存储在我的数据库中的表格。 i want to retrive the images but its has not been giving me the images on the screen. 我想检索图像,但是它没有给我屏幕上的图像。 instead , it write long alphabeth of different symbols . 而是写了不同符号的长字母。

below is my codes , pls help me out. 以下是我的代码,请帮帮我。 thanks 谢谢

    $sql = "SELECT * FROM `file` WHERE id = 8";
    $mq = mysqli_query($dbconnect, $sql) or die ("not working query");
    $row = mysqli_fetch_array($mq) or die("line 44 not working");
    $s=$row['data'];
    echo $row['data'];

   echo '<img src="'.$s.'" alt="HTML5 Icon"      style="width:128px;height:128px">';

what is wrong with my codes please. 请问我的代码有什么问题。

thanks 谢谢

Because you say you see lots of characters instead of the filename, I assume that you don't store a path to that image (then you could use src as you tried to use), but the image content itself and that it is jpg (you can change to png or whatever type you have there). 因为您说看到的是很多字符而不是文件名,所以我假设您没有存储该图像的路径(然后可以尝试使用src来使用),但是图像内容本身是jpg(您可以将其更改为png或其他类型)。 If so, use data URI syntax for src: 如果是这样,请对src使用数据URI语法:

$src = "data:image/jpg;base64,".base64_encode($row['data']);
echo '<img src="'.$src.'" alt="HTML5 Icon" style="width:128px;height:128px">';

It is called data URI - you can read more about it for example here: https://en.wikipedia.org/wiki/Data_URI_scheme 它称为数据URI-例如,您可以在此处了解更多信息: https : //en.wikipedia.org/wiki/Data_URI_scheme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM