What are the limitations of using functions like mime_content_type or finfo_file to determine MIME types in PHP?

The limitations of using functions like mime_content_type or finfo_file in PHP to determine MIME types is that they rely on the system's MIME database, which may not always be up-to-date or accurate. To solve this issue, you can use a more reliable method like the Fileinfo extension, which provides more accurate MIME type detection by analyzing the actual file content.

// Using the Fileinfo extension to determine MIME type
$file = 'example.jpg';
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime_type = $finfo->file($file);
echo "MIME type of $file is: $mime_type";