How can the "Undefined index" error related to file upload be resolved in PHP?

When uploading a file in PHP, the "Undefined index" error occurs when trying to access the file input field using its name, but the file was not successfully uploaded to the server. This error can be resolved by checking if the file input field is set using the isset() function before processing the file upload.

if(isset($_FILES['file_input_name'])){
    // Process file upload
    $file = $_FILES['file_input_name'];
    // Continue with file upload logic
} else {
    // Handle case when file input is not set
    echo "File input not set.";
}