function _filefield_source_remote_mime_extension in FileField Sources 7
Get/set the remote file extension in a static variable.
2 calls to _filefield_source_remote_mime_extension()
- filefield_source_remote_value in sources/
remote.inc - A #filefield_value_callback function.
- _filefield_source_remote_parse_header in sources/
remote.inc - Parse cURL header and record the filename specified in Content-Disposition.
File
- sources/
remote.inc, line 306 - A FileField extension to allow referencing of existing files.
Code
function _filefield_source_remote_mime_extension($curl_mime_type = NULL) {
static $extension = NULL;
if (isset($curl_mime_type)) {
include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
$curl_mime_type = drupal_strtolower($curl_mime_type);
$mapping = file_mimetype_mapping();
// See if this matches a known MIME type.
$map_id = array_search($curl_mime_type, $mapping['mimetypes']);
if ($map_id !== FALSE) {
// If we have a match, get this list of likely extensions. For some reason
// Drupal lists the "most common" extension last for most file types
// including php, jpg, and doc.
if ($extensions = array_keys($mapping['extensions'], $map_id)) {
$extension = end($extensions);
}
}
}
return $extension;
}