Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Menampilkan gambar dari database menggunakan php
Ini script upload.php
<?php
include_once('connection/connect.php');
$title = $_POST['title'];
$content = $_POST['content'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$query = "INSERT INTO `post`(post_title, post_content, post_picture) VALUES('$title', '$content', '{$image}')";
if (mysqli_query($connect, $query)) {
echo "success!";
header('Location:dashboard.php');
}else{
echo "failed!";
}
?>
Ini home.php
<div class="container">
<div class="navbar-inverse">
<div class="row">
<div class="grid">
<?php
include_once('connection/connect.php');
$query = "SELECT * FROM `post` ORDER BY `post`.`post_id` DESC" ;
$result = mysqli_query($connect, $query);
?>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
<a href="#">
<div class="col-4">
<div class="col">
<div class="box-img">
<img src="" alt="">
</div>
<div class="box-content">
<div class="title">
<b><?php echo $row['post_title']; ?></b>
</div>
<span class="time">
<p class="fa fa-clock-o"> 10:10pm</p>
</span>
<p class="clearfix content"><?php echo $row['post_content']; ?></p>
</div>
</div>
</div>
</a>
<?php } ?>
</div>
</div>
</div>
</div>
Pertanyaan nya bagaimana menampilkan gambar di home.php? gambar yang saya simpan di database menggunakan type BLOB. Terimakasih
0
1 Jawaban:
coba ini gan
<img src="data:image/jpeg;base64,<?php echo $row['post_picture']; ?>" alt="" />
1