What are potential pitfalls when using $_FILES and isset in PHP for file uploads?

One potential pitfall when using $_FILES and isset in PHP for file uploads is not checking if the file upload was successful before processing the uploaded file. This can lead to errors or security vulnerabilities if the file was not uploaded properly. To solve this, you should first check if the file upload was successful using isset() and then proceed with processing the uploaded file.

if(isset($_FILES['file_upload']) && $_FILES['file_upload']['error'] === UPLOAD_ERR_OK){
    // File upload was successful, process the uploaded file
    $file_name = $_FILES['file_upload']['name'];
    $file_tmp = $_FILES['file_upload']['tmp_name'];
    
    // Process the uploaded file here
} else {
    // File upload was not successful, handle the error
    echo "File upload failed";
}