PHP rename() Function

PHP rename Function


Define :

In this tutorial we have to learned about PHP rename() Function.The rename() function is inbuilt function in php.The PHP rename() function attempts to rename a file or directory, moving it between directories if necessary. If renaming a file and newname exists, it will be overwritten. If renaming a directory and newname exists, this function will raise a warning.

Syntax
   rename(oldname, newname, context)
Parameters
oldname Required. Specify the file or directory to be renamed.
newname Required. Specify the new name for the file or directory.
context Optional. Specify the context of the file handle. Context is a set of options that can modify the behavior of a stream.

Example :

Output : test.txt is renamed to demo.txt.