How can the move_uploaded_file function be used effectively in PHP to save uploaded files to a specific directory?

To save uploaded files to a specific directory in PHP, you can use the move_uploaded_file function. This function moves an uploaded file to a new location. To use it effectively, you need to specify the temporary file path of the uploaded file and the destination directory where you want to save it.

$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];

if (move_uploaded_file($uploadedFile, $destination)) {
    echo "File uploaded successfully.";
} else {
    echo "Failed to upload file.";
}