In this article, you will learn how to change the name of a file or folder in PHP. The rename() function in PHP renames a file or directory.
what is the syntax of the RENAME function in php?
rename(old, new, context)
|old||Required. Specifies the file or directory to be renamed|
|new||Required. Specifies the new name for the file or directory|
|context||Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream|
examples of the RENAME function
Example 1. In this example, we rename a directory + a file.
<?php rename("images","pictures"); rename("/test/file1.txt","/home/docs/my_file.txt"); ?>