In Drupal's current version, file_check_upload() sets $file->filemime based on $_FILES["edit"]["type"][$source];

In Drupal 4.6, file->filemime was set based on mime_content_type().

In my opinion, the solution adopted in Drupal 4.6 used to be much more reliable. In the way 4.7 is setup, there are many cases in which the MIME type of common uploaded files is not recognized and is set to "unknown/unknown" which does not provide much help for modules such as audio.module that rely on that information...

Would it be possible to change the current version of file_check_upload() so that it matches the way it used to be in 4.6?

Tks in advance,

Leo

Comments

dopry’s picture

Assigned: Unassigned » dopry
Status: Active » Closed (won't fix)

Filemime was removed due to issues with open_basedir. Filemime also was not set based on mime_content_type. Mime content type was simply used for validation.

 if (function_exists('mime_content_type')) {
      $file->filemime = mime_content_type($file->filepath);
      if ($file->filemime != $_FILES["edit"]["type"][$source]) {
        watchdog('file', t('For %file the system thinks its MIME type is %detected while the user has given %given for MIME type', array('%file' => theme('placeholder', $file->filepath), '%detected' => theme('placeholder', $file->filemime), '%given' => theme('placeholder', $_FILES['edit']['type'][$source]))));
      }
    }
    else {
      $file->filemime = $_FILES["edit"]["type"][$source];
    }

mime_content_type is also deprecate in php, all of mime-magic is, to be replaced by fileinfo that lives in PECL. see http://us3.php.net/manual/en/ref.mime-magic.php.

The old functionality of mime_content_type in 4.6 would not provide you improve mime recognition. It would only prevent you from uploading improperly identified files, so it wouldn't help modules such as audio, that need to identify mime types.

leoburd’s picture

Hello there,

Thanks for your comments. Unfortunately, I'm new to PHP/Drupal and I'm not sure I understood what you were trying to say.

From my understanding, on the very example that you gave, filemime is being set by mime_content_type():

$file->filemime = mime_content_type($file->filepath);

Moreover, as you said, the usage of mime_content_type() "prevent you from uploading improperly identified files", and that's something that we need in audio.module, otherwise users will be uploading files that, although common, will not be recognized by that module (I've got a bunch of examples where that happened).

Finally, fileinfo seems to be still an experimental function, doesn't it?

Please let me know what you think,

Best,

Leo