ExpressionEngine

2.11.9 User Guide

Retired Documentation

You are using the documentation for version 2.11.9. Go here for the latest version or check here for your available upgrades to the latest version.

Mime Type Class

Calling the Mime Type Class

class Mime_type

ExpressionEngine uses the Mime Type class whenever a file’s, or buffer’s, Mime type needs to be determined. Additionally, it is used to dertermine if a file is an image, and to determine if a file is safe for uploading. This class is a library, so you have to load the Mime Type library before using it:

ee()->load->library('mime_type');

Note

The Mime Type library uses the Mime Type whitelist file at system/expressionengine/config/mimes.php when determining if a file is safe for uploading or is an image.

Note

There is a mime_whitelist_additions config override for adding installation specific Mime Types to the whitelist.

Note

There is a mime_whitelist_member_exception config override and a mime_whitelist_member_group_exception config override which will bypass the whitelist for those members and/or member groups.

Methods

Mime_type::getWhitelist()

Returns the whitelist of Mime Types

Returns:An array of Mime types that are on the whitelist
Return type:array
Mime_type::ofFile($path)

Determines the Mime type of a file

Throws:

Exception If the file does not exist

Parameters:
  • $path (string) – The full path to the file being checked
Returns:

The Mime type of the file

Return type:

string

Mime_type::ofBuffer($buffer)

Determines the Mime type of a buffer

Parameters:
  • $buffer (string) – The buffer/data to check
Returns:

The Mime type of the buffer

Return type:

string

Mime_type::fileIsImage($path)

Determines if a file is an image or not.

Throws:

Exception If the file does not exist

Parameters:
  • $path (string) – The full path to the file being checked
Returns:

TRUE if it is an image; FALSE if not

Return type:

bool

Mime_type::isImage($mime)

Determines if a Mime type is in our list of valid image Mime types.

Parameters:
  • $mime (string) – The mime to check
Returns:

TRUE if it is an image; FALSE if not

Return type:

bool

Mime_type::fileIsSafeForUpload($path)

Gets the Mime type of a file and compares it to our whitelist to see if it is safe for upload.

Throws:

Exception If the file does not exist

Parameters:
  • $path (string) – The full path to the file being checked
Returns:

TRUE if it safe; FALSE if not

Return type:

bool

Mime_type::isSafeForUpload($mime)

Checks a given Mime type against our whitelist to see if it is safe for upload

Parameters:
  • $mime (string) – The mime to check
Returns:

TRUE if it is an image; FALSE if not

Return type:

bool