Home >Backend Development >PHP Problem >How to rename a file using php
How to implement PHP renaming: first create a PHP sample code; then use the rename function to rename the file or directory. The syntax is "rename(oldname, newname, context)"; finally execute the file. .
Definition and usage
rename() function renames a file or directory.
If successful, the function returns true. On failure, returns false.
Syntax
rename(oldname,newname,context)
Parameters
oldname required. Specifies the file or directory to be renamed.
newname Required. Specifies the new name of the file or directory.
context Optional. Specifies the environment for a file handle. context is a set of options that modify the behavior of the stream.
Tips and Notes
Note: Prior to PHP 4.3.3, rename() could not rename files across disk partitions on *nix-based systems.
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.
Example
<?php rename("images","pictures"); ?>
For more related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to rename a file using php. For more information, please follow other related articles on the PHP Chinese website!