What is the correct method in PHP to check if a file has been selected for upload before submitting a form?

When submitting a form that includes a file upload field, it's important to check if a file has been selected before processing the form data. This can prevent errors or unexpected behavior when handling the file upload. One way to do this in PHP is by checking if the $_FILES array contains the file information for the uploaded file.

if(isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name'])) {
    // File has been selected for upload, proceed with processing the form data
} else {
    // File has not been selected, display an error message or take appropriate action
}