4

我通过下面的代码将图像路径插入到数据库中,但我无法在 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);
?> 
4

1 回答 1

5
echo "<img src='".$row['photo']."' />";
于 2013-01-04T21:40:31.930 回答