我创建了一个具有画廊上传功能的网站。
上传效果完美无瑕,但不会在网页上显示图像。
我在代码中找不到错误
我尝试将图像显示为我创建的框的背景图像,并使用带有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>
答案 0 :(得分:0)
您使用了错误的语法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>';
}