我正在尝试将上传的图片从Mysql渲染到一个名为result.php的文件中,这是将图片上传到Mysql的代码。
include ('connect.php');
//if button with the name uploadfilesub has been clicked
if(isset($_POST['uploadfilesub'])) {
//declaring variables
$filename = $_FILES['uploadfile']['name'];
$filetmpname = $_FILES['uploadfile']['tmp_name'];
//folder where images will be uploaded
$folder = 'imagesuploadedf/';
//function for saving the uploaded images in a specific folder
move_uploaded_file($filetmpname, $folder.$filename);
//inserting image details (ie image name) in the database
$sql = "INSERT INTO `uploadedimage` (`imagename`) VALUES ('$filename')";
$qry = mysqli_query($conn, $sql);
if( $qry) {
echo "</br>image uploaded";
}
}
?>上传的图像保存在我的服务器上名为imagesuploadedf的文件夹中
我使用下面的代码在result.php上渲染图像,但它只显示文件名,我需要渲染图像。
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = 'SELECT * from uploadedimage';
if (mysqli_query($conn, $sql)) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$count=1;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) { ?>
<tbody>
<tr>
<td>
<?php echo $row['imagename']; ?>
</td>
</tr>
</tbody>
<?php
$count++;
}
} else {
echo '0 results';
}
?>
</table>要在页面上显示/渲染上传的图像,我需要在result.php上写些什么?
发布于 2021-03-07 01:42:55
您应该编写一个HTML页面,其中包含引用您想要显示的图像的
它可能看起来像这样:
<td>
<?php
$imgTag = '<img src="/imagesuploadedf/' . $row['imagename'] . '" />';
echo $imgTag; ?>
</td>这会把类似这样的东西放到你的网页上。
<td>
<img src="/imagesuploadedf/image_file_name"/>
</td>如果您的网页来自https://images.example.com,这将使浏览器从您的服务器下载https://images.example.com/imagesuploadedf/image_file_name格式的图像并将其显示在页面中。
https://stackoverflow.com/questions/66508093
复制相似问题