How can the use of strtolower() function prevent errors when checking file extensions in PHP?

When checking file extensions in PHP, using the strtolower() function can prevent errors by converting the file extension to lowercase. This is important because file extensions are case-sensitive, and comparing them in a case-insensitive manner ensures accurate results. By converting the file extension to lowercase, you can avoid issues related to mismatched cases.

$file_extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));

// Example usage:
if ($file_extension === 'pdf') {
    echo 'This is a PDF file.';
} else {
    echo 'This is not a PDF file.';
}