What you want to do is perform a query in the foreach loop to insert the image name and / or location into your table at the same time you're uploading the image.
You'd also want to make sure that it really is an image to prevent people from uploading malicious stuff.