The php Function Rename
The php function rename() allows you to rename files and directories. It takes two parameters: oldName and newName as well as an optional context resource.
The first parameter, oldName, specifies the name of the file or directory that you want to rename. The second, newName, specifies the name of the file that you want to rename it to. The last, context, is a set of options able to alter the behavior of the stream that is used to rename the file or directory.
Note that rename() can fail on some filesystems, especially when trying to move files that have been opened and closed. This can result in the file being deleted, even though it still exists on the filesystem and its contents have been written to. A workaround for this is to copy the file (if necessary) and then use unlink().
A bug in rename() on UNIX systems may cause it to fail if the destination filesystem mounts a filesystem with an explicit uid and gid (eg. if it is mounted with "uid=someuser,gid=somegroup"). This can trigger warnings in rename() which can be confusing unless you understand the underlying mechanics.
Another issue is that rename() does not properly follow *nix rename rules when moving a file or directory. This can lead to problems on XP machines, where you can end up with a directory that only has half of its content present. If you need to do a proper rename on XP, I suggest using the copy() and unlink() functions rather than rename().