Is it recommended to use exec() or system() functions for renaming files in PHP?

It is not recommended to use exec() or system() functions for renaming files in PHP as they can pose security risks if not properly sanitized. Instead, it is safer to use built-in PHP functions like rename() which provide a more secure way to rename files.

$old_file = 'old_file.txt';
$new_file = 'new_file.txt';

if (rename($old_file, $new_file)) {
    echo 'File renamed successfully.';
} else {
    echo 'Error renaming file.';
}