What are common functions in PHP for moving and renaming files, both locally and on an FTP server?

To move and rename files in PHP, you can use the `rename()` function for local files and the FTP functions provided by PHP for files on an FTP server. For local files, `rename()` can be used to move and rename files within the same directory or to a different directory. For files on an FTP server, you can use functions like `ftp_rename()` to move and rename files.

// Move and rename a local file
$oldFilePath = 'oldfile.txt';
$newFilePath = 'newfile.txt';

if (rename($oldFilePath, $newFilePath)) {
    echo 'File moved and renamed successfully.';
} else {
    echo 'Error moving and renaming file.';
}

// Move and rename a file on an FTP server
$ftpServer = 'ftp.example.com';
$ftpUsername = 'username';
$ftpPassword = 'password';
$oldFile = 'oldfile.txt';
$newFile = 'newfile.txt';

$ftpConn = ftp_connect($ftpServer);
ftp_login($ftpConn, $ftpUsername, $ftpPassword);

if (ftp_rename($ftpConn, $oldFile, $newFile)) {
    echo 'File on FTP server moved and renamed successfully.';
} else {
    echo 'Error moving and renaming file on FTP server.';
}

ftp_close($ftpConn);