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']);
    }
  }
CommentFileSizeAuthor
mimetype.patch1.23 KBcasey
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Boris Mann’s picture

Category: bug » feature

This looks like a good addition. Marking as feature request for new code.

skilip’s picture

Status: Needs review » Closed (won't fix)

The Drupal 5 branch will not be longer supported