Best method to generate unique filenames when uploading files PHP(上传文件 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 时生成唯一文件名的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:上传文件 PHP 时生成唯一文件名的最佳方法


基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01