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

查看:1176
本文介绍了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天全站免登陆