Create Unique Image Names

前端 未结 15 2189
暗喜
暗喜 2021-01-06 08:02

What\'s a good way to create a unique name for an image that my user is uploading?

I don\'t want to have any duplicates so something like MD5($filename) isn\'t suita

15条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 08:26

    You could take a hash (e.g., md5, sha) of the image data itself. That would help identify duplicate images too (if it was byte-for-byte, the same). But any sufficiently long string of random characters would work.

    You can always rig it up in a way that the file name looks like:

    /image/0/1/012345678/original-name.jpg
    

    That way the file name looks normal, but it's still unique.

提交回复
热议问题