Home  >  Article  >  Backend Development  >  How to use php rename function

How to use php rename function

藏色散人
藏色散人Original
2019-02-21 13:52:553901browse

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 php rename function

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn