Home >Backend Development >PHP Tutorial >How to use php rename function
PHP rename() function is used to rename a file or directory. The syntax "rename(file old name, new name, handle environment)" changes the old name of the file or directory using the new name specified by the user, and Can be moved between directories as needed; returns True on success and False on failure.
#How to use the php rename() function?
Function: Rename files or directories.
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.
Return value: Returns True when successful and False when failed.
Note: The encapsulation protocol used in oldname must match the one used in newname.
php rename() function example
<?php $file = "test.txt"; $res = rename($file,"index.txt"); if($res) { echo "文件重命名成功"; }else{ echo "文件重命名失败"; } ?>
This article is about the use of the rename function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use php rename function. For more information, please follow other related articles on the PHP Chinese website!