I normally use the db to name the files so that there are no problems with overwriting existing images.
So if I were uploading a thumbnail of a user it would have a prefix of "user_" and be stored in a directory /image/user/thumbs/ for example.
When the file is uploaded the first thing I do is assign a unique number (I use auto_increment column) to the image so it can be saved without the risk of overwriting any existing image.
Then you move the uploaded image to the corresponding folder using the name "$prefix.$unique_number".
Then when you come to retrieve the image from the db you have the text to put in the "src" attrib for the <img>.
If you search on here or Google there are lots of complete examples of this sort of script with explanations.
Hope this helps 😉