Hi Guys,

I have been trying to display the images from the database with the code below. Images are not displayed.

      <?php while($product_data = mysqli_fetch_array($query_product_result))
        $num_rows_products = $num_rows_products - 1;

        Print "<div class='image_panel'><a href = 'products.php?prodid=" . $product_data["ID"] . "'><img src='data:image/jpeg;base64," . base64_encode($row['image']) . "' alt='' /></a></div>";
        Print "<h2><a href = 'products.php?prodid=" . $product_data["Item_ID"] . "'>" . $product_data["name"] . "</a></h2>";
        Print "<ul><li>Price: &pound;" . $product_data["Item_price"] . "</li><li>Availability: ";

        Print "<p>" . $product_data["description"] . "</p>";
        if($num_rows_products > 0)
                Print '<div class="cleaner_with_height">&nbsp;</div>';
3 Years
Discussion Span
Last Post by almostbob


it could be the mime-type or the column table size, be sure to not truncate the input. If using a blob column type then this can support up to 65536 bytes. To save more data use mediumblob which supports up to 16MB or longblob which supports up to 4GB.

The same applies if you're saving them as encoded strings, use mediumtext or longtext instead of text.

Docs: http://dev.mysql.com/doc/refman/5.6/en/storage-requirements.html

Edited by cereal


are you sure it isnt $product_data["image"] seems strange to have one column not from the same array ($row[]) as the others

OR. are db images already encoded base64 in the db ?
not common, most images are stored in blob, but there are many very quirky programmers, security by obscurity etc.
Print "<div class='image_panel'><a href = 'products.php?prodid=" . $product_data["ID"] . "'><img src='data:image/jpeg;base64," . $row['image'] . "' alt='' /></a></div>";

Edited by almostbob

Votes + Comments
nice catch!

Thanks Guys!

Almost Bob you are right.

I tried the code below and it works!

Print "<div class='image_panel'><a href = 'products.php?prodid=" . $product_data["ID"] . "'><img src='data:image/jpeg;base64," . base64_encode($product_data["image"]) . "' alt='' /></a></div>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.