PHP Tutorial Rename () function
PHP filesystem functions
Definition and usage
The rename () function renames the file or directory.
If successful, the function returns True. If it fails, it returns false.
Grammar
Rename (Oldname,newname,context)
Parameters |
Description |
Oldname |
Necessary. Specifies the file or directory to be renamed. |
NewName |
Necessary. Specify a new name for the file or directory. |
Context |
Necessary. Specifies the environment for file handles. Context is a set of options for modifying the behavior of a stream. |
Hints and Notes
Note: rename () cannot rename files across disk partitions in a *nix-based system until PHP 4.3.3.
Note: The encapsulation protocols used in Oldname must match those used in newname.
Note: support for the context is added by PHP 5.0.0.
Example
OldPath----file or directory original path
$newpath----a new defined path
Then rename ($oldpath, $newpath) will be able to complete the operation of File/directory move
Through my tests, Win32 and UNIX versions of PHP4 support this feature.
Also, as if PhP4 's Win32 version cancels the unlink () function. You can also use the rename () function to complete the removal operation, for example:
$path----file or directory path
$TMP----tmp directory (/tmp)
Move the file to the TMP directory with rename ($path, $tmp).
http://www.bkjia.com/PHPjc/445427.html www.bkjia.com true http://www.bkjia.com/PHPjc/445427.html techarticle PHP Tutorial rename () function PHP filesystem function definition and usage rename () function to rename a file or directory. If successful, the function returns True. If it fails, it returns false. Grammar ...