The problem is when I receive email attachments images/binary data becomes corrupted however when I upload files to the same database table they aren't corrupted.
On the left side is the normal image that works (when renamed to PHP and it's binary data is copied). The right side is the image after it's been corrupted. I figured I'd add the image because someone may see it and just know what is going on here. PHP code below...
So I have other files including images stored in the database and they work just fine...
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
//INSERT INTO table (data), ($data);//etc
However the error is occurring in the PHP code that I use to clean up emails and then store them in the database along with attached files. I know that the attached files are being targeted in PHP correctly so it's simply HOW I'm storing it which seems to be the problem. The data column in MySQL is longblob
and uploading images before sending them works fine but when I RECEIVE emails this code that handles putting received attachments is what breaks (using the same database table).
$data = mysqli_real_escape_string($connection,base64_decode($email['attachments'][$t]['attachment']));
$data = mysqli_real_escape_string($connection,$email['attachments'][$t]['attachment']);
$data = base64_decode($email['attachments'][$t]['attachment']);
$data = mysql_real_escape_string(base64_decode($email['attachments'][$t]['attachment']));
$data = addslashes($email['attachments'][$t]['attachment']);