0

How can I get an Image from a mysql database and echo it to the screen??

I have this script to get the information from the database:

/* check connection */ if (mysqli_connect_errno()) { echo("Connection Error: ". mysqli_connect_error()); } else { $query = "SELECT * FROM games"; if ($result = mysqli_query($link, $query)) { /* fetch associative array */ $row = mysqli_fetch_assoc($result); } } 

but when I try to echo the image to the screen I get this:

ï öË>Ti¥òŦ„u`¨c’–÷½µÏÿøå[Kuu‹].YW\Æ3dŒä Þ|ÊÐkµa_êøÊwþ”c~n•…æjoÈÔ^r¸dbt~8Ø|•33ID ꨣVc&”Ñ£H¡::Ó_/þ8Àuæ£-¶edWHÂ5Þ’Lf:ä>œv*Jk¬±ŽÈ([å´³*«qÀÓŸ"uÀ%$š—¹Õf^¾Ä ¯ªøú«[öÐó_ZNDpÀºì²[ÄYï,‹–¼i©C/Ðê¨È‡Oôò–£FÕ–h£QúÖq+¥Qƒ¹Á0E˜¾°Ym©¬XPd‘oYDe¼…ţϳÐâ!íwúX °mÍú¨?n݆^®mí:‡Â5ðàF<è¼R“œíZñœ‹Ö6«’-0ŠyØÐ*ròw¼<ñ$³ÿC[Ë¡§^[ßZQƒFÔ D h! \³Hï[À¬Ú´kÔ=Šaè\«Ïþ+«®Ñ…3ú‰Ç'WõÛbŒ‚liƒ°ØjãŒ6ÚF ÇvÛÿ ÎÖ(PÇQ÷ç ÃVTh:cS÷Ä8ˆŠ9ïµ´¶§*®åËÍ:äü°Ø”£­Ãs”×VÖûÄ£ùZ’xúòuCh:y?ªÈéh¶ƒšjŽû£ 

except much longer.

How can I echo the image??

Thanks.

1 Answer 1

2

Add this before echoing the image:

header('Content-Type: image/png'); 

P.S: instead of image/png, you should put proper content type like image/gif or image/jpg.

Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't that display the image on a new page?
No, that line just tells your browser the content it's receiving is an image!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.