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

时间:2013-01-04 21:29:46

标签: php

我通过下面的代码将图像路径插入到数据库中,但是我无法在html页面中显示它...图像的路径是"images/"我如何显示实际图像?我努力了但是我开始工作的最多的是显示文件名而不是图像。

<?php
$mysqli = new mysqli("localhost", "root", "", "simple_login");

// TODO - Check that connection was successful.

$photo= "images/" . $_FILES["file"]["name"];

$stmt = $mysqli->prepare("INSERT INTO photo (photo) VALUES (?)");

// TODO check that $stmt creation succeeded

// "s" means the database expects a string
$stmt->bind_param("s", $photo);

$stmt->execute();

$stmt->close();

$mysqli->close(

?>

这是我试图显示图像...这只显示带路径的文件名.....

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("simple_login", $con);

$result = mysql_query("SELECT * FROM photo");

while($row = mysql_fetch_array($result))
{
echo $row['photo'];
echo "<br />";
}

mysql_close($con);
?> 

1 个答案:

答案 0 :(得分:2)

echo "<img src='".$row['photo']."' />";