What is the purpose of the move_uploaded_file function in PHP and how is it typically used?

The move_uploaded_file function in PHP is used to move an uploaded file to a new location on the server. This function is typically used after a file has been uploaded via a form submission and allows the file to be securely saved to a specified directory on the server.

if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $uploadedFile = $_FILES['file']['tmp_name'];
    $destination = 'uploads/' . $_FILES['file']['name'];
    
    if (move_uploaded_file($uploadedFile, $destination)) {
        echo 'File uploaded successfully!';
    } else {
        echo 'Error moving file.';
    }
} else {
    echo 'Error uploading file.';
}