[英]Image from database does not display on web page
i am trying to display the image on web page from database , but it just displayed the file name of my image on web page我试图从数据库中在网页上显示图像,但它只是在网页上显示了我的图像的文件名
the code for fetching image is获取图像的代码是
<?php
error_reporting(0);
$query = "SELECT * FROM blog_posts";
$data = mysqli_query($link, $query);
$total = mysqli_num_rows($data);
while ($result = mysqli_fetch_assoc($data)) {
echo $result['title'] . "<br>" . $result['author'] . "<br>" . $result['file_name'] . "<br>" . $result['body'] . "<br>";
}
?>
just change this line只需改变这一行
echo $result['title'] . "<br>" . $result['author'] . "<br> <img src '" . $result['file_name'] . "'><br>" . $result['body'] . "<br>";
but you should get the full directory of file not just name or you should write it like this但是你应该得到文件的完整目录而不仅仅是名称,或者你应该像这样写
$file_name ="/dir/dir/".$result['file_name'];
and after that you can put the $filename in img tag like this echo "<img src='$file_name'>";
之后你可以把 $filename 放在 img 标签中,就像这样
echo "<img src='$file_name'>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.