我在mysql数据库中存储了一个图像,但是我试图在我的php页面中显示它,但该图像不显示。
我尝试了几个论坛创意,但没有成功
查看:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name 46.101.134.111;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
控制器:
<div class="container">
<?php
echo "<img src='data:image/png;base64,".base64_encode($gebruiker->profileImage)."' alt='profielfoto'>";
?>
</div>
型号:
$this->load->model('gebruiker_model');
$data['gebruiker'] = $this->gebruiker_model->get($id);
检查:
function get($id)
{
$this->db->where('id', $id);
$query = $this->db->get('gebruiker');
return $query->row();
}
我希望显示的图像存储在我的数据库中,但不显示。 图片是PNG。
答案 0 :(得分:0)
使用base64_encode
<div class="container">
<?php
echo "<img src='data:image/png;base64,".base64_encode($gebruiker->profileImage)."' alt='profielfoto'>";
?>
</div>
答案 1 :(得分:0)
在插入Blob文件时,请使用file_get_contents()函数。
并了解更多有关此内容,可以参考此内容 链接:Image upload to MySQL database blob in codeigniter