0

My website stores pictures in a TEXT mysql field and displays them like:

extract of database:

data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4QBGRXhpZgAASUkqAAgAAAABADEBAgAjAAAAGgAAAAAAAABieS5ibG9vZGR5LmNyeXB0by...

and they are displayed that way

<img id="image" style="width:160px;" src="<?=$row["data"];?>">

I would like some images to be accessible directly like in browser: http://www.mysite.com/myPicture.php?id=1 (id=field 1 of database)

(with no html, just pure JPEG image)

so it returns a pure JPEG image (I guess some headers to be stup as JPEG).

Any clue for that ?

enter image description here

yarek
  • 11,278
  • 30
  • 120
  • 219

2 Answers2

1

I am pretty sure you can get around that with MIME Headers (http://en.wikipedia.org/wiki/MIME_type) that will be sent to the browser so that it knows how to interpret the data that it is being fed and display it correctly as an image (or whatever type of data you are sending to the user).

<?php
header('Content-Disposition: inline');
header('Content-type: image/png');
echo "yourImageData";
?>
Fluffeh
  • 33,228
  • 16
  • 67
  • 80
-2

Simply remove data:image/png;base64, from the beginning of the data, base64_decode the rest of it – and output that decoded data after a header('Content-Type: image/png') … done.

CBroe
  • 91,630
  • 14
  • 92
  • 150