Hi Guys,
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?
Hi Guys,
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?
You need to escape it properly:
mysql_query('INSERT INTO table (picture) VALUES ("'
. mysql_real_escape_string($image) . '")');
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.