What best practice should be followed when handling file uploads in PHP to avoid undefined index errors?

When handling file uploads in PHP, it is important to check if the file input field exists in the form submission to avoid undefined index errors. This can be done by using the isset() function to verify if the file input field is set before accessing its properties. By following this best practice, you can prevent errors when trying to access file upload data that may not exist in the form submission.

if(isset($_FILES['file_input'])) {
    // File upload logic here
    $file_name = $_FILES['file_input']['name'];
    $file_tmp = $_FILES['file_input']['tmp_name'];
    $file_size = $_FILES['file_input']['size'];
    $file_type = $_FILES['file_input']['type'];
    
    // Process the uploaded file
} else {
    // Handle case when file input field is not set
}