简体   繁体   English

如何显示存储在数据库中的图像?

[英]How to display an image that is stored in the database?

<?php
   $query = "SELECT * FROM table WHERE id = 2";
   $result = mysqli_query($con, $query);
   $result_set = mysqli_fetch_array($result);
   echo $result_set['img'];
?>

Why do shows strange characters, not image? 为什么要显示奇怪的字符,而不是图像?

You need to add Content-Type header at the beginning, something like 您需要在开头添加Content-Type标头,例如

<?
  header('Content-Type: image/png');
?>

for the PNG image 对于PNG图像

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

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