从MySQL显示图像而不是回显

时间:2018-07-31 02:02:45

标签: php html image mysqli

除了像这样回显图像之外,还有另一种将图像从MySQL放置到html的方法:

  echo "<img src='images/" . $row['event_image'] . "' height='200' width='320' class=responsivez> ";

我正在尝试将图像路径放到html标签上。 getImage.php显示我的图像路径,但是在下一页上调用时,图像不显示。我缺少一些重要的语法吗?

<img src="images/getImage.php?" width="175" height="200" />

getImage.php

<?php
$con=mysqli_connect("localhost","root","","blast");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
} 
$state='Johor';
$result=mysqli_query($con,"SELECT * from blast_events where 
event_state='$state'");

if (!$result) {
die ('SQL Error: ' . mysqli_error($con));
}
else{    
}
$row=mysqli_fetch_array($result);

echo $row["event_image"];
?>

1 个答案:

答案 0 :(得分:0)

尝试输出图像而不只是路径:

   header('Content-Type:image/jpeg');
   readfile($row["event_image"]); // make sure the path is valid not only filename.
// echo $row["event_image"];