Php 如何从数据库中存储的路径显示图像?
我通过下面的代码将图像路径插入到数据库中,但我无法在html页面中显示它…图像的路径是Php 如何从数据库中存储的路径显示图像?,php,Php,我通过下面的代码将图像路径插入到数据库中,但我无法在html页面中显示它…图像的路径是“images/”如何显示实际图像?我很努力,但我得到的最多的工作是显示文件名,而不是图像 <?php $mysqli = new mysqli("localhost", "root", "", "simple_login"); // TODO - Check that connection was successful. $photo= "images/" . $_FILES["file"]["na
“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(
?>
echo”“;
尝试使用带有标记的文件名。为什么在顶部使用mysqli_
,然后在底部使用mysql_
?此外,顶部使用PDO,但底部使用不推荐的方法。您是否确实将上载的图像存储在某个位置?我使用echo“”代码>但未显示图像。
<?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);
?>
echo "<img src='".$row['photo']."' />";