0

I try save to database attachments in base64 format

$sql = "INSERT INTO `attachments`(mp_id, at_source, at_format)
                        VALUES(".$id.", '".$attach['data']."', '".$attach['mimetype']."'  )
                ";

Gettings error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '€čH•zøŻU… ¨@' at line 2

I think something is wriong with '' quotes , how to insert base64 encoded file source ?

I'm add attachment: http://pastebin.com/srYbHTAS

Wizard
  • 10,985
  • 38
  • 91
  • 165

1 Answers1

0

Your data is not base64 encoded. You try to insert the raw attachment data.

$sql = "INSERT INTO `attachments`(mp_id, at_source, at_format)
                        VALUES(".$id.", '".base64_encode($attach['data'])."', '".$attach['mimetype']."'  )";

Base64 looks like something like this:

TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=

Jan
  • 46
  • 3