上传文件 PHP 时生成唯一文件名的最佳方法 [英] Best method to generate unique filenames when uploading files PHP

查看:39
本文介绍了上传文件 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.

这篇关于上传文件 PHP 时生成唯一文件名的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆