Forum Moderators: coopster
I am coding a section to a website which shows the members of a sports team, along with their photos. I am also creating a form to allow admins to update/insert members, along with their photos.
So far (thanks to the help of you guys!) I have working code to alter a members details and to upload an image to the server. However I have not yet linked the code to upload a photo to the members section.
The members table is very simple in that it only has a few fields like name, bio etc. I want another field in this table that holds the filename of any uploaded photo.
So my questions are:
1) How do I link the uploaded file to an entry in the members table?
2) How do I check that the filename does not already exist in the upload folder?
3) Is this approach the best way, if not what are my alternatives?
I would assume your members each have their own unique id, so you could add a row in the upload table that holds the id for this member. Your query would fetch each image based on the member id.
With regards to the filename, easiest way would be to make your filename table UNIQUE in your database, this would prevent any data being duplicated. Or you could use the file_exists() function to check if the image has already been uploaded and if it has display an error. Another way you could do it is to add a prefix to the file name if the image already exists. If all you want is to prevent images being over written, this may be an idea. Its up to you.
I would think your approach is fine and best of luck with your execution.
:)