Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
flash gives every kind of file an application/octet-stream mime-type. This gives problems with for example the slideshow.module which uses the mimetype for selecting images.
Adding something like this to _swfupload_swfupload() may do the trick:
// mime-type is always application/octet-stream when using flash for uploading
if($_FILES['Filedata']['type'] == 'application/octet-stream') {
if (function_exists('finfo_open')) {
$f = finfo_open(FILEINFO_MIME);
$mime = finfo_file($f, $_FILES['Filedata']['tmp_name']);
finfo_close($f);
$_FILES['Filedata']['type'] = $mime;
}
elseif (class_exists('finfo')) {
$f = new finfo(FILEINFO_MIME);
$_FILES['Filedata']['type'] = $f->file($_FILES['Filedata']['tmp_name']);
}
elseif (strlen($mime=@shell_exec("file -bi ".escapeshellarg($_FILES['Filedata']['tmp_name'])))!=0) {
//Using shell if unix an authorized
$_FILES['Filedata']['type'] = trim($mime);
}
elseif (function_exists('mime_content_type')) {
//Double check the mime-type with magic-mime if avaible
$_FILES['Filedata']['type'] = mime_content_type($_FILES['Filedata']['tmp_name']);
}
}
Comment | File | Size | Author |
---|---|---|---|
mimetype.patch | 1.23 KB | casey |
Comments
Comment #1
Boris Mann CreditAttribution: Boris Mann commentedThis looks like a good addition. Marking as feature request for new code.
Comment #2
skilip CreditAttribution: skilip commentedThe Drupal 5 branch will not be longer supported