我的程序需要上传图片,因此图片(varchar)位置保存在MySQL数据库中。它工作到目前为止。如何使用PHP显示来自数据库的图像?
现在我想要显示图像,这是行不通的。下面是代码:
include ('connect.php');
if(isset($_POST['submit'])){
$filetemp= $_FILES['image'] ['tmp_name'];
$filename= $_FILES['image'] ['name'];
$filepath= "images/".$filename;
move_uploaded_file($filetemp,$filepath);
$sql=mysqli_query($con,"insert into images (image) value ('$filepath')");
if($sql){
echo "uploaded";
}
else{
echo " not uploaded";
}
}
$sql=mysqli_query($con,"select * from images");
while($row=mysqli_fetch_array($sql)){
echo "<img src=' images/".$row['image']."'>"; // the problem is here, its just displaying img icon, not actual image
}
?>
什么是存储在'图像'在数据库? 'img'标签中的路径在'images /' – RamRaider
之前有一个前导空格,这是保存在图像列“images/download.jpg”中的值。 –