[ale] PHP hates JPG

Mike Harrison meuon at geeklabs.com
Wed Nov 26 09:55:17 EST 2008


> I am using php to build a web page (duh!). The images are placed based on a
> database lookup for the images file name. Apparently, once php gets that
> file name it parses it as more php code. So any jpg with a ?> or other php
> indicator character pattern is not displayed and my httpd error logs file
> with "PHP Warning:  Unexpected character in input:  '\x07' (ASCII=7) state=1
> .." messages.
>
> I _KNOW_ php can do this properly as a gazillion sites do this all the time.

While I'll content storing image blobs isn't my favorite way of doing 
this.. and not all of my tricks work in all browsers or PHP installs. .
Tricks include (this is for a PNG, but can also work for other types)


Cut and pasted:

#works for everything but MSIE < 8 - Oh.. Just 70% of the web. Sure is sexy though.
ob_start(); imagepng($image); $imgdata = ob_get_contents(); 
ob_end_clean(); $img = base64_encode($imgdata); imagedestroy($image);
print "<img border=\"0\" src=\"data:image/png;base64," . htmlentities($img) . "\" alt=\"embedded graph\">" ;





More information about the Ale mailing list