我在网上找到了一些代码来实现访问我的数据库,以检索带有MIME扩展名的存储文件,并将该信息读取到我存储实际图像的目录中.Link to the code source个
<div id="display-image">
<?php
$query = " select * from image ";
$result = mysqli_query($db, $query);
while ($data = mysqli_fetch_assoc($result)) {
?>
<img src="./image/<?php echo $data['filename']; ?>">
<?php
}
?>
</div>
在我访问数据库的每个实例中,我都喜欢使用DIE或EXIT(0).然而,当我try 在此代码中使用它时,页面无法正确加载.以下是我的编码方式:
<?php
// This page uploads to profile pic into the profile page
include("database_connection.php");
$user = $_SESSION['active_user']['username'];
$get_img = "SELECT * FROM test WHERE User='$user' LIMIT 1";
$runit = mysqli_query($db,$get_img);
while($pic = mysqli_fetch_assoc($runit))
{
?>
<img src="img/<?php echo $pic['image_file01']; ?>" >
<?php
exit(0);
}
?>
所以上面的代码在一个单独的文件中,我在我的个人资料页面上包括了这个文件,如下所示:
<div class="body-align-left">
<br><br>
<!-- Profile Image-->
<?php
include('upload.php');
?>
</div>
尽管代码看起来运行得很好,但我不太确定使用While语句是否是解决这一问题的最佳方法.另外,我想知道这个代码到底有多安全.什么是更好的方法?正如我在上面所说的,如果我试图在代码块中使用Exit(0)或die,它不会完全加载页面.