Home > Article > Backend Development > The wonderful use of the rename() function in php_PHP tutorial
As we all know, the rename() function can rename files or directories. In fact, it can do a lot of things.
Friends who are familiar with Unix should know the shell command mv, which is equivalent to win32 movement, and can be renamed while moving. I found that php's rename() function is equivalent to mv. It not only has a simple renaming function, but can also change the path of files or even entire directories.
For example:
$oldpath ----The original path of the file or directory
$newpath ----New definition path
Then rename($oldpath,$newpath) can complete the file/directory moving operation
After my testing, both win32 and unix php4 versions support this function.
In addition, it seems that the win32 version of php4 has canceled the unlink() function. Then you can also use the rename() function to complete the deletion operation, for example:
$path ---- file or directory path
$tmp ---- tmp directory (/tmp)
Use rename($path,$tmp) to move the file to the tmp directory.