html - PHP: How to display TEXT data image directly in browser?

723

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" class="page_speed_1025506044" 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

149

Answer

Solution:

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

Answer

Solution:

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

People are also looking for solutions to the problem: php - Picasa video wordpress

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.