How can a shared hosting environment affect the availability of PHP extensions like mime_content_type()?

In a shared hosting environment, the availability of PHP extensions like mime_content_type() depends on the server configuration set by the hosting provider. If the extension is not enabled by default, you may need to contact your hosting provider to request its activation or consider using an alternative method to determine the MIME type of a file.

// Check if the mime_content_type() function is available
if (function_exists('mime_content_type')) {
    $mime_type = mime_content_type('path/to/file.jpg');
    echo "MIME type: " . $mime_type;
} else {
    // Alternative method to determine MIME type
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime_type = finfo_file($finfo, 'path/to/file.jpg');
    finfo_close($finfo);
    echo "MIME type: " . $mime_type;
}