file_get_mimetype

Versions
5 – 6
file_get_mimetype($filename, $mapping = NULL)
7
file_get_mimetype($uri, $mapping = NULL)

Determine an Internet Media Type, or MIME type from a filename.

see file_default_mimetype_mapping()

Parameters

$uri A string containing the URI, path, or filename.

$mapping An optional map of extensions to their mimetypes, in the form:

  • 'mimetypes': a list of mimetypes, keyed by an identifier,
  • 'extensions': the mapping itself, an associative array in which the key is the extension (lowercase) and the value is the mimetype identifier. If $mapping is NULL file_mimetype_mapping() is called.

Return value

The internet media type registered for the extension or application/octet-stream for unknown extensions.

Related topics

▾ 4 functions call file_get_mimetype()

file_save_data in includes/file.inc
Save a string to the specified destination and create a database file entry.
file_save_upload in includes/file.inc
Saves a file upload to a new location.
system_theme_settings_submit in modules/system/system.admin.inc
Process system_theme_settings form submissions.
user_update_7004 in modules/user/user.install
Add the user's pictures to the {file} table and make them managed files.

Code

includes/file.inc, line 1708

<?php
function file_get_mimetype($uri, $mapping = NULL) {
  if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {
    return $wrapper->getMimeType($uri, $mapping);
  }
  else {
    // getMimeType() is not implementation specific, so we can directly
    // call it without an instance.
    return DrupalLocalStreamWrapper::getMimeType($uri, $mapping);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.