English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP rename() Function Usage and Example

PHP Filesystem Reference Manual

The rename() function can rename files or directories, and this function returns true on success and false on failure.

Syntax

bool rename ( string $oldname , string $newname [, resource $context ] )

This function attempts to rename oldname to newname and move between directories if necessary. If renaming a file and a new name exists, the file can be overwritten. If renaming a directory and a new name exists, this function will issue a warning.

Online Example

<?php
   rename("/PhpProject/sample.txt"/PhpProject/php/sample1.txt");
   echo "File renaming successful!";
?>

Output Result

File renaming successful!

PHP Filesystem Reference Manual