Solution to duplicate file names when uploading multiple images in tp5.0 (explanation with examples)

不言
Release: 2023-04-05 12:22:02
forward
2790 people have browsed it

The content of this article is about the solution to the duplicate file name of uploading multiple pictures in tp5.0 (explanation with examples). It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. helped.

Recently, a problem occurred while working on a project. Let’s record it here:

Problem:

Use the files that come with the TP5.0 framework After uploading the method, I found that the problem of duplicate file names may occur when uploading multiple images.

Problem code:

Find the TP5 framework upload file naming method, /thinkphp/library/think/File.php file, buildSaveName method (line 394);

case 'date':
    $savename = date('Ymd') . DS . md5(microtime(true));
    break;
Copy after login

Solution:

The file naming method can be modified;

case 'date':
    //$savename = date('Ymd') . DS . md5(microtime(true));
    $savename = date('Ymd') . DS . md5(uniqid(md5(microtime(true)),true));
    break;
Copy after login

The above is the detailed content of Solution to duplicate file names when uploading multiple images in tp5.0 (explanation with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template