I have a database table which contains receipt images, encoded into BLOB data in PHP. The table has the following columns and data:
id | ownerid | file | filename | size | type | fileerror
-----|---------|------|---------------------|--------|------------|-----------
1644 | 9 | BLOB | 2014-03-0714.30.jpg | 996379 | image/jpeg | NULL
The file type was captured on original upload via a webform using one of either iMagick or GD, converted to a blob, and stored in the database.
The schema may have been converted from MyISAM to InnoDB at some point. The encoding may have been converted from Latin1 to UTF8-unicode-ci at some point. It may also have always been set thus.
I have subsequently tried all of the methods of converting the BLOB back to an image I can think of, however I never end up with an image.
I've tried using Imagick::readImageBlob($myBlob)
and ended up with a big fat file which doesn't want to be an image, and I've tried using imagecreatefromstring($myBlob)
.
I'm using file_put_contents()
to save the file.
I gather BLOBs are binary, and should stay binary, and the encoding should not effect them... however I cannot get my blobs to be pictures anymore.
How can I figure out if:
- My binary blobs are corrupted in the database, and I should give up.
- My binary blobs are fine thanks, and my PHP skills are failing me.
- Some kind of character encoding thing is happening behind the scenes in php I can fix.
I just tried saving the blob straight to a file from mysql workbench, and that didn't help either.
Edit: A little taste of blob (taken from the file I dumped, via chrome)
/9j/4FwwEEpGSUZcMAEBAVwwYFwwYFwwXDD/4Vww8kV4aWZcMFwwTU1cMCpcMFwwXDAIXDAMAVwwXDADXDBcMFwwAQmQXDBcMAEBXDADXDBcMFwwAQcsXDBcMAEPXDACXDBcMFwwBE