Thinkphp5 custom upload file name

In these days do tp5 upload files module, the project needs is to put the file name is changed after uploading user name + combination of the original file name on the Internet looking for a moment does not seem to find a similar article. . . I had no choice but to study their own study.

Before looking over to see the official manual clouds above, file upload that one is really talking about is vague, it is for our students to project self-knowledge tp5 everywhere blind ah.

Tp5 file related operations modules in thinkphp \ library \ think \ File.php inside, we find move 335 lines () function

  

/ **
* Move files
* @access public
* @param String $ path save path
* @param string | bool $ savename save the default file name is automatically generated
* whether @param boolean $ replace the same file cover
* @return false | File
* /

   public function move($path, $savename = true, $replace = true){

Written above $ savename is a String or bool type, so direct incoming file name or file name variable on the line

Write in their own relevant code:

$saveName = 'Tom';
$info = $file->move('./Upload',$saveName,false);

Re-upload you can see the uploaded file has been modified for Tom.

Deposit into the database name is Tom, the documentation is completely changed the name.

Thus available, what features need to go directly to the frame of the file to look inside, feeling more than a detailed look at the manual!

 

Guess you like

Origin www.cnblogs.com/rowan88/p/11229705.html