0

I want to enter some image file that is in ../img/test.jpg into the database

If I do $image = file_get_contents('../img/test.jpg')

And then mysql command "INSERT into table(picture) VALUES ('$image')" it doesn't work.

Any suggestions?

1
  • 3
    And “doesn’t work” means what? Do you get any error messages? Commented Jul 13, 2009 at 7:49

2 Answers 2

6

You need to escape it properly:

mysql_query('INSERT INTO table (picture) VALUES ("'
    . mysql_real_escape_string($image) . '")');
Sign up to request clarification or add additional context in comments.

1 Comment

Oops, fixed. Too used to "?" style
-2

Keep the image on the filesystem. You're making MySQL work too hard sending the image through a socket to your PHP script. Then you make Apache work too hard while PHP is blocking waiting for the image data from MySQL.

I don't see a valid reason why you want to save it as a mysql Blob. It gets written to the filesystem anyway by mysql.

Just save the path in MySQL.

1 Comment

those who down voted this answer could write a comment and explain why this answer is not good

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.