• PHP Video Tutorials

PHP - Function rename()



The rename() function can rename a file or directory, and this function can return true on success, or false on failure.

Syntax

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

This function can attempt to rename oldname to newname, moving it between directories if necessary. If renaming a file and newname exists, it can be overwritten. If renaming a directory and newname exists, this function can emit a warning.

Example

<?php
   rename("/PhpProject/sample.txt", "/PhpProject/php/sample1.txt");
   echo "file renamed successfully";
?>

Output

file renamed successfully
php_function_reference.htm
Advertisements