I'm writing a web application where users can upload images. I wonder what's the best practice of assigning unique names to images ? I thought MD5 can ben useful and enough, but since each image has an owner, do I have to use MD5 ? I mean it could be enough to rename with Userid + imagename + creationdate ?
How to assign unique names to images?
322 views Asked by iva123 At
2
There are 2 answers
0
On
No, it would not be enough as the user might want to upload several images with the same name.
The easiest solution is to use a sequence number with the image name. You can be certain that there is no other image with the same name and there will never be one. With a hash function there is always an ever so slight chance of collision.
Your database gives you a unique ID for each record. Though there are many different ways to do what you want, it is usually best to use this ID as a prefix/suffix to the name of the image. So, for these records:
you could display something like:
15_image.png
,23_image.png