Jump to content

[SOLVED] Can you upload images directly to MySQL?


aim25

Recommended Posts

Sure, you can put the data in a PHP variable and INSERT it into a MySQL BLOB column as you would normally.  Use mysql_real_escape_string() to escape anything that would break the query.

 

$image = file_get_contents('image location...'); // or from $_FILES or whatever
mysql_query(sprintf('INSERT INTO images (image) VALUES ("%s")',mysql_real_escape_string($image));

 

That simple example should work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.