Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ErMandeep/f6fb349b302ec01d15220b1d39d3d303 to your computer and use it in GitHub Desktop.
Save ErMandeep/f6fb349b302ec01d15220b1d39d3d303 to your computer and use it in GitHub Desktop.
Encripted image insert and fetch from database in php ( save image in database without upload move to any folder )
<?php
// image upload query
if(count($_FILES["image"]["tmp_name"]) > 0)
{
for($count = 0; $count < count($_FILES["image"]["tmp_name"]); $count++)
{
$image_file = addslashes(file_get_contents($_FILES["image"]["tmp_name"][$count]));
$query = "INSERT INTO images (productID, image) VALUES ('$id_guests', '$image_file')";
$result= mysqli_query($connection,$query);
}
}
?>
<!-- fetch blob images -->
<?php
$view_images = "SELECT * FROM images WHERE productID= $productID";
$select_imgs = mysqli_query($connection, $view_images);
while($row = mysqli_fetch_assoc($select_imgs)){
$id_img = $row['id'];
$img = $row['image'];
?>
<img src="data:image/jpeg;base64,<?php echo base64_encode($img); ?>" style="height:220px; width:220px; " />
<a href="vendor-dashboard-add-listing.php?p_id=" class= "trash" >Remove</a>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment