Upload image to Mysql with PHP fails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ZaphoidYK
    New Member
    • Aug 2014
    • 2

    Upload image to Mysql with PHP fails

    Hi..

    I am really bashing my head on this one. I have an image I have manipulated, now I want to push it back to the database.

    So, to accomplish this, I have the following:

    --- $image_file = fopen ('/var/tmp/tmp.jpg','rb');
    $image_data = fread ($image_file, filesize ('/var/tmp/tmp.jpg'));
    $image_data = addslashes ($image_data);
    fclose ($image_file);


    $sql = "UPDATE article_attachm ent SET content = $image_data where id = $article_data[0]";

    $image_update = mysql_query ($sql);

    echo mysql_error($db i);
    ---
    It's more drawn out than it should be, but I am breaking everything down to try and solve this. I get the 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 '▒▒▒▒\0JFIF\0\0 \0\0\0\0▒▒\0>CR EATOR: gd-jpeg v1.0 (using IJG JPEG v62), defa' at line 11"

    I see some high order characters that don't appear to be getting escaped properly, should this be happening?...

    Thanks,
    Richard.
  • ZaphoidYK
    New Member
    • Aug 2014
    • 2

    #2
    Found the issue. In my sleep deprived state, I had reused the $image_data variable. It was already an array, and I was re-casting image data into it. Made for some confusion.

    Comment

    Working...