Hello,
I am parsing a mailbox using the imap functions, pulling out images
attached and putting them into mySQL as BLOB fields. I am having
problems displaying images once they are stored in mySQL, and I think
it may be related to the way I store them.
The following line of code is called after an attachment has been
identified as a GIF attachment:
$rawimage = addslashes(imap_fetchbody($mbox,$m,$part_c));
....where $mbox is the imap link and so forth.
Testing to make sure I am actually pulling info out, a debug line like:
print_r($rawimage);
....displays a bunch of chars that are the image attachment data, and a
line like:
print_r(base64_decode($rawimage));
....displays other, different chars.
Looks good so far - I'm definitely pulling images out as raw data.
So I INSERT the $rawimage into my blob field.
However, on the display page, I send the headers like:
header("Content-type: image/gif");
[get image from database and store it in a var called $image_from_db]
echo $image_from_db;
But I get a broken image...
So I try print_r($image_from_db) on this page (after removing the
header line) and it looks like the chars from the tests before - it's
the same data.
base64_decode($image_from_db) does not make the image display properly,
either, but printing it as such shows all those chars again.
I think I do not understand how base64 encoding and addslashes works
between MIME, php and mySQL. Anybody have any ideas? How should I
format the data when I pull it out of MIME (in terms of base64
decoding), how should I insert it (addslashes is correct?) and how
should I echo it when I pull it out into the displaying php image
generation page?
I have a feeling someone has had this problem before out there :)