0

i have this prob. when i try to retrieve a BLOB image from database it returns a broken image any help ?? this is the code after connecting and fetching an array:

 <img src='",$row['pic'],"' width='331px' height='200px' />
user2864740
  • 60,010
  • 15
  • 145
  • 220
  • `src` should point to a URI that outputs the image, it shouldn't be the image data itself. Or, you could try a data URI: http://en.wikipedia.org/wiki/Data_URI_scheme – Wesley Murch May 09 '14 at 18:51
  • 1
    http://stackoverflow.com/questions/1636877/how-can-i-store-and-retrieve-images-from-a-mysql-database-using-php , http://stackoverflow.com/questions/13214602/how-to-display-an-blob-image-stored-in-mysql-database?rq=1 , http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database - so many related questoins, but I can't find a *duplicate* because this question is too vague about the problem and misses basic comprehension points. – user2864740 May 09 '14 at 18:56

1 Answers1

2

That's not how img tags work. You essentially have two choices:

  • Create a PHP file which outputs only the image (probably based on a query string parameter to get the image from the database) with the correct Content-Type and use the URL of that file as the src attribute.
  • Use a Data URI scheme to directly display the data in the img tag.

The latter would look something like this:

src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="

Where everything after the comma in the src value is the image data base64-encoded.

David
  • 208,112
  • 36
  • 198
  • 279