Browse Source

Fix MimeDetect to allow checking MIMEs for multiple mapped values.

pull/433/head
Jordan Dukart 11 years ago
parent
commit
d4783db6a3
  1. 5
      includes/add_datastream.form.inc
  2. 15
      includes/mime_detect.inc

5
includes/add_datastream.form.inc

@ -161,7 +161,10 @@ function islandora_add_datastream_form_validate(array $form, array &$form_state)
if (isset($form_state['datastream_requirements'][$dsid]) && $file) { if (isset($form_state['datastream_requirements'][$dsid]) && $file) {
$allowed_types = $form_state['datastream_requirements'][$dsid]['mime']; $allowed_types = $form_state['datastream_requirements'][$dsid]['mime'];
$mime_detect = new MimeDetect(); $mime_detect = new MimeDetect();
$allowed_extensions = array_map(array($mime_detect, 'getExtension'), $allowed_types); $allowed_extensions = array();
foreach ($allowed_types as $mime) {
$allowed_extensions = array_merge($allowed_extensions, $mime_detect->getValidExtensions($mime));
}
$errors = file_validate_extensions($file, implode(' ', $allowed_extensions)); $errors = file_validate_extensions($file, implode(' ', $allowed_extensions));
if (count($errors) > 0) { if (count($errors) > 0) {
form_set_error('file', $errors[0]); form_set_error('file', $errors[0]);

15
includes/mime_detect.inc

@ -383,4 +383,19 @@ class MimeDetect {
return $this->protectedMimeTypes; return $this->protectedMimeTypes;
} }
/**
* Get all valid extensions for this MIME type.
*
* @param string $mimetype
* The MIME type we are searching for.
*
* @return array
* An array of valid extensions for this MIME type.
*/
public function getValidExtensions($mimetype) {
$filter = function($mime) use ($mimetype) {
return $mime == $mimetype;
};
return array_keys(array_filter($this->protectedMimeTypes, $filter));
}
} }

Loading…
Cancel
Save