Skip to content
Advertisement

How to fetch images from database in base64_encode in php

Thank you all in advance…. I am doing a project in which I have a field to store the image. In that form, the image uploaded is completed with croppie plugin. and I stored the data in base 64 encodings. But I cannot fetch it to a page called view.php but the images are fetched to the form after cropping.

Please help me to figure it out the mistake that I have done

<tbody>
    <?php
    $no = 1;
    $data = mysqli_query($con, "SELECT * FROM `register`  WHERE app_registration IS NULL   ORDER BY `app_id` DESC ");
    while ($row = mysqli_fetch_assoc($data)) {
    ?>
        <tr>
            <td><?php echo $row['app_id'] ?></td>
            <?php if (!empty($row['image_reference_id'])) {
                $data1 = mysqli_query($con, "SELECT * FROM `photo_table`  WHERE image_unique_id = '" . $row['image_reference_id'] . "'");
                $row1 = mysqli_fetch_assoc($data1)
                ?>
                <td><img src="data:image/jpg;base64,'.base64_encode($row['images']).'"/></td>
            <?php } else {
                ?>
                <td><img src="../images/<?php echo $row['app_image'] ?>" style="width: 100px;     height: 100px;"></td>
            <?php } ?>
            <td><?php echo $row['app_name'] ?></td>
            <td><?php echo $row['app_mobile_no_1'] ?></td>
        </tr>
    <?php } ?>
</tbody>

Note: In db the images are in Long Blob

Advertisement

Answer

You will need to change the following:

<img src="data:image/jpg;base64,'.base64_encode($row['images']).'"  />

to

<img src="data:image/jpg;base64, <?php base64_encode($row['images']);?>"  />
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement