上传文件 PHP 时生成唯一文件名的最佳方法

2022-01-09 00:00:00 image unique upload identifier php

任何人都可以建议为文件上传生成唯一文件名以避免重复的最佳做法参赛作品?

Can any one suggest the best practice to generate unique file names for file uploads to avoid duplicate Entries?

提前致谢.

推荐答案

我通常要么使用 uniqid() 函数为文件名创建一个 UID,要么使用上传文件的用户名创建一个文件夹并保留原始文件文件名.第一个的缺点是您必须将原始文件名保存在某个地方才能显示给用户.

I usually either create a UID using uniqid() function for the filename or create a folder with the name of the username who is uploading the file and leave the original filename. The disadvantage of the first one is that you will have to save the original filename somewhere to show to the user.

相关文章