Are there any potential security risks associated with using load data local infile in PHP?

Using the "load data local infile" function in PHP can pose security risks, such as allowing potential SQL injection attacks or unauthorized access to files on the server. To mitigate these risks, it is important to properly sanitize user input and validate file paths before using the function.

// Sanitize user input and validate file path before using load data local infile
$filename = $_POST['filename'];
$filename = filter_var($filename, FILTER_SANITIZE_STRING);

if (file_exists($filename)) {
    $query = "LOAD DATA LOCAL INFILE '$filename' INTO TABLE table_name";
    // Execute the query
} else {
    // Handle invalid file path
}