This article mainly introduces the usage of rename() function in php. It analyzes the meaning of parameters in the rename() function and the specific usage method in more detail. It has certain reference value and needs Friends can refer to
This article analyzes the usage of the rename() function in PHP with examples. Share it with everyone for your reference. The details are as follows:
php
filesystem function, rename() function renames a file or directory. If successful, the function returns true. If it fails, false is returned.
Statement: rename(oldname,
newname,context)
##Parameters
Description |
| ##oldname
Required, specifies the file or directory to be renamed. |
| newname
Required, specifies the new name of the file or directory |
| context
Required, specifies the environment of the file handle, context is the modifiable stream Behavior | 's set of options |
Note
: Prior to PHP 4.3.3, rename() could not be renamed across disk partitions on *nix-based systems. Name the file.
Note: The encapsulation protocol used in oldname must match the one used in newname.
Note: Support for context was added in PHP 5.0.0.
The code is as follows:
<?php
rename("images","pictures");
?>
Copy after login
oldpath ---- the original path of the file or directory, $newpath ---- the new defined path, then rename($oldpath,$newpath) can be completed 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, so you can also use rename cleverly () function to complete the
delete
operation, for example:
$path ---- file or directory path
$tmp ---- tmp directory (/tmp )
Use rename($path,$tmp) to move the file to the tmp directory.
The above is the detailed content of How to use the rename() function in php. For more information, please follow other related articles on the PHP Chinese website!