I don't have exact code for you but this is basically how I did it for my sites.
when you upload the file it sends it to a temp directory with a temp file name.
in the $_POST array there is a field that i think says tmpname or something similar.
input that file into a string to your script and then take that string and store it into the database. you will need to put it into some sort of BLOB field. and depending on how you do it you may need to pull the mime type of the file.
to pull the image and view it in a browser you will need to make a script to query that BLOB field of the table and do createImagefromString (i think is what the function is). you will also need to change the headers of that script to tell the browser that it is an image.
I have read that many people frown on making galleries this way because it is slower. If you index the database right, it is not that bad. It also makes it more difficult for people to steal your images. Most people do not realize they can just rename the image 😃