Mysql upload image[mediumblob]

Well, I’ve never tried it myself but I think something like this might start the job off:

$file_immagine = $_FILES['img']['tmp_name'];
$file_image_contents = file_get_contents($file_immagine); // load image file
   $sql = "INSERT INTO articoli (titolo, testo, img)
   VALUES ('$titolo', '$testo', '$file_image_contents')";

BUT. I can’t imagine that will work without somehow encoding the binary image data. I’ve read about using addslashes() after loading the image contents, but I’m sure someone else can comment on whether that’s still a current way to do things.

Another approach suggested in an older thread on here is to modify the query:

 $file_immagine = $_FILES['img']['tmp_name'];
   $sql = "INSERT INTO articoli (titolo, testo, img)
   VALUES ('$titolo', '$testo', LOAD_FILE('$file_immagine'))";

In the same thread there is discussion on the pros and cons of storing the image data directly inside the database table. Inserting and then retrieving a blob data from mysql database using php - #7 by felgall