How to use php rename function

藏色散人
Release: 2023-04-05 11:14:01
Original
3964 people have browsed it

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)
Copy after login

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 "文件重命名失败";
}
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!