我已经创建了一个具有画廊上传功能的网站。
上传完美无缺,但网页上没有显示图片。
我找不到代码中的错误
我已尝试将图像显示为我创建的框的背景图像,并带有带有属性 src 的图像标签。
最后一种方法显示网站正在读取图片,但无法显示。
<div class="wrapper">
<h2>Art Gallery</h2>
<div class="Gallery-container">
<?php
include_once 'includes/dbh.inc.php';
$sql = "SELECT * FROM gallery1 ORDER BY orderGallery DESC";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed!";
} else{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
echo '<a href="#">
<div><img src=url(gallery/img/'.$row["imgfullnameGallery"].');></div>
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</a>';
}
}
?>
</div>
<?php
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/galleryupload.inc.php" method="post" enctype="multipart/form-data">
<input type="text" name="filename" placeholder="File name...">
<input type="text" name="filetitle" placeholder="Title...">
<input type="text" name="filedesc" placeholder="Description...">
<input type="file" name="file">
<button type="submit" name="submit">UPLOAD</button>
</form>
</div>';
}
?>
</div>
最佳答案
您使用了错误的语法 img 标签 请更新以下代码
while ($row = mysqli_fetch_assoc($result)) {
echo '<a href="#">
<div><img src="gallery/img/'.$row["imgfullnameGallery"].'"></div>
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</a>';
}
关于php - 我在从数据库到页面显示图像时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199294/