You are here

function file_get_type in File Entity (fieldable files) 7

Same name and namespace in other branches
  1. 7.3 file_entity.file_api.inc \file_get_type()
  2. 7.2 file_entity.file_api.inc \file_get_type()

Determines the file type of a passed in file object.

The file type is determined by extracting the 'first' part of the file's MIME type. For example, a PNG image with a MIME type of 'image/png' will have a file type of 'image'.

IANA list of official MIME media types

1 call to file_get_type()
file_entity_file_presave in ./file_entity.module
Implements hook_file_presave().

File

./file_entity.file_api.inc, line 55
API extensions of Drupal core's file.inc.

Code

function file_get_type($file) {

  // Ensure that a MIME type has been determined first.
  if (empty($file->filemime)) {
    $file->filemime = file_get_mimetype($file->uri);
  }
  return substr($file->filemime, 0, strpos($file->filemime, '/'));
}