Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

rename()

Example

Rename a directory or file.

<?php
rename(“images”,“pictures”);
rename(“/test/file1.txt”,“/home/docs/my_file.txt”);
?>

Definition and Usage

The rename() function changes the name of a file or directory.

Syntax

rename(oldnewcontext)

Parameter Values

Parameter

Description

old

Required. Specifies the file or directory to rename.

new

Required. Specifies the new name for the file or directory.

context

Optional. Specifies the context for the file handle, which is a set of options that can alter the behavior of the stream.

Technical Details

 

Return Value:

Returns TRUE on success, FALSE on failure.

PHP Version:

4.0+

PHP Changelog:

PHP 5.3.1 introduced support for renaming files across drives on Windows.

PHP 5.0 added the ability to use rename() with certain URL wrappers.