0

I asked a question earlier regarding retrieving a image from a database; as my query was not working properly. This is now working to some extent, as the query now works,correct image name appears and a placeholder box with a question mark in the middle where the image should be.

In my earlier post, i was directed to a number of posts, to fix the image not appearing image. I followed the posts by adding:

echo'<img src="data:image/jpeg;base64,' . base64_encode($img) . '" alt="Category_header" 
width="100%" height="300px">';

To my code, however it is still now working, I know you can use a header, but i am really trying to avoid that method, unless it is the more efficient way.

This is what i am receiving at the present moment:

enter image description here

Code

           mysqli_report(MYSQLI_REPORT_INDEX);
    if (isset($_GET['rest_id'])) {

        $Rest = $_GET['rest_id'];

        $get_cat_img = "SELECT Cuisine_category,Category_img
             FROM Rest_Category
             INNER JOIN Rest_Details
             ON Rest_Category.CategoryID = Rest_Details.Cat_ID
             WHERE Rest_Details.Resturant_ID='$Rest'";

        $results = mysqli_query($dbc, $get_cat_img) or die("query is not working");
        $row=mysqli_fetch_array($results) or die ("q not working");
        $img=$row['Category_img'];
        echo $row['Category_img']; //shows the category_img name

        //            echo '<img src="'.$img.'" alt="background" style="width:100%;height:300px">';
       echo'<img src="data:image/jpeg;base64,' . base64_encode($img) . '" alt="Category_header" width="100%" height="300px">';  

    }
    mysqli_close($dbc);
Community
  • 1
  • 1
Monroe
  • 177
  • 11
  • 2
    I think you will find that you should have base64encoded the image before storing it on the database. – RiggsFolly May 08 '16 at 15:49
  • http://stackoverflow.com/questions/1636877/how-can-i-store-and-retrieve-images-from-a-mysql-database-using-php – RiggsFolly May 08 '16 at 15:52
  • Another thing to check is that the BLOB field was created LARGE enough to hold all the image. Its easy to end up with only part of the picture loaded on your database unless you stored them very carefully,checking ALL possible errors during the process. Are you sure you have the whole image in your database – RiggsFolly May 08 '16 at 15:58
  • @RiggsFolly hi again lol. That example uses a header, is that a more efficient way. – Monroe May 08 '16 at 16:01
  • @RiggsFolly i used a long blob for this purpose to ensure i have also save images above 65 – Monroe May 08 '16 at 16:02
  • There are also lots of other errors that can happen, remember an image is a binary and therefore an contain what looks like odd characters that will make PHP or MYSQL think it sees and end-of-file somewhere in the middle of a picture file. You are going to have to show us how you stored these images otherwise we have no idea what errors we are looking for – RiggsFolly May 08 '16 at 16:02
  • Hi: Well I would test the images on your database. If they are complete and usable you should be able to SELECT the image and write it to disk. If you can then read that disk file with your favourite image viewer then the image files are consistent when read from the database. If not, well you damaged the file when you stored them – RiggsFolly May 08 '16 at 16:05
  • @RiggsFolly i saved the images in a folder, then inserted the images url as seen in our tutorials into the database. The image in the question prints the image source url. Will show create show you ? – Monroe May 08 '16 at 16:12

0 Answers0