-3

I am trying to display an image from my database but it isn't showing on the website. How do i get the image to display through php?

Database set up

Database Setup

Php code

print "    <td><img src='Img.php?id=" . $row["id"] . "' /></td>";
TheKaiser4
  • 149
  • 1
  • 1
  • 11
  • Your should provide full php code where you want to show this image and what you have done till now – Arsh Singh Nov 09 '15 at 14:04
  • you might need to post the contents from `img.php` as that is where all the magic happens – Professor Abronsius Nov 09 '15 at 14:04
  • What is the code in Img.php and it looks like you are actually uploading the image in the database? See here http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – Dipen Shah Nov 09 '15 at 14:04
  • Saving the image in the database is not recommended try to upload the image to a file in the server and save the image path in the database – Mahmoud.M Nov 09 '15 at 14:07

1 Answers1

1

1st guess, the img column contains a link in which case it will be

echo " <td><img src='" . $row["img"] . "' /></td>";

2nd guess, the img column is base64 encoded image in which case it will be

echo " <td><img src='data:image/gif;base64," . $row["img"] . "' /></td>";

I think, that is off the top of my head.(if image is gif, amend accordingly)

3rd guess, some wizardry going on? perhaps img.php is doing the base64 decode for you?

I would recommend storing the image on disk or S3 or something then storing the path in the DB.

Matt The Ninja
  • 2,641
  • 4
  • 28
  • 58