rename()
Instead of copying a file, we may want to move it to a different directory without leaving the original. With rename() we can do that.
This function can also be used to change a file’s name. It works on directories too.
As with copy(), if we’re moving the file or directory, the directory we’re moving it into must already exist. See mkdir().
$res = rename( 'temp/test.txt', 'temp/this.txt' ); if( false === $res ) { echo 'Rename failed!'; } // Moving the "temp" directory into the "other" directory which does exist // And renaming "temp" to "temp2" $res = rename( 'temp', 'other/temp2' );
See the manual entry for rename()
