Reputation: 1381
Imagine I'm building a blog system where a user can upload images for a blog post. I have a problem mapping the uploaded images with user and their blog post.
Here's the flow :
User uploaded some pictures, it's saved to the server.
I store the image name in the related table, means later I can retrieve images by blog's post_id.
But what if the user upload images that has the same file name?
Upvotes: 0
Views: 94
Reputation:
Append a serial ID to every file name, such as an integer that you increment every time.
Upvotes: 1
Reputation: 964
You could go for a file name that's structured like
userID_blogpostID_filename
Oh and as for the same file name problem, just do a simple check, and rename the file if a file of the same name exists.
And as manudog's answer suggested, you could add the unix time along with the filename to avoid that from happening.
Upvotes: 1