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>';
            }
      }
      ?>

Hi,

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

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.
try
Print "<div class='image_panel'><a href = 'products.php?prodid=" . $product_data["ID"] . "'><img src='data:image/jpeg;base64," . $row['image'] . "' alt='' /></a></div>";

commented: nice catch! +13

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>";

Too good, glad to help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.