I'm running Drupal 4.7b2 and having a problem with a mismatch between the MIME type sent by the browser (for uploaded files) and the MIME type that the server thinks the file has. The warning, which comes from file.inc, looks like this:

<code>For /tmp/php5Jc9L0 the system thinks its MIME type is application/x-zip while the user has given application/x-zip-compressed for MIME type

For /tmp/phpIqDVKH the system thinks its MIME type is text/plain while the user has given application/pdf for MIME type

Running:
Debian Sarge
Apache/1.3.33
PHP 4.3.10-16
Drupal 4.7b2

Comments

Savant-1’s picture

same problem, on Ubuntu. Breezy. Apache 2, php 5. Also have modrewrite on. File permissions should be good. Can't get avatars to work... still searching for clues...

"For /tmp/phpsCNagt the system thinks its MIME type is while the user has given image/jpeg for MIME type"

Mime type is ... blank?

~Savant

Ainur’s picture

Same problem, Drupal 4.6.x, Apache/2.0.54 (Debian), PHP/4.3.10-16

For /tmp/phph4arsf the system thinks its MIME type is image/jpeg while the user has given image/pjpeg for MIME type

This happens with any file I try to upload.

fago’s picture

i had the same problem some time ago.

if your php is compiled with mime_magic, file.inc will use it. in my case, it used the wrong mime magic file (php setting mime_magic.magicfile). i changed it to use the magic file, which comes with apache and now everything is fine.

killes@www.drop.org’s picture

Which path has the file that worked for you?
--
Drupal services
My Drupal services

fago’s picture

i used /etc/apache2/magic, which is part of sarge's apache2-common package

killes@www.drop.org’s picture

I tried /etc/apache/mime.types from apache1 and that did not work. This is not surprise because the files have a different format. I still think this is rather a Drupal bug.
--
Drupal services
My Drupal services

fago’s picture

perhaps it is, too.

from the php documentation:
You must compile PHP with the configure switch --with-mime-magic to get support for mime-type functions. The extension needs a copy of the simplified magic file that is distributed with the Apache httpd.

i changed that,
(from /usr/share/misc/file/magic.mime) and now it works.

killes@www.drop.org’s picture

My current configuraton does work once I apply this patch:

http://drupal.org/node/43220

The mime type does get correctly identified.
--
Drupal services
My Drupal services

Ainur’s picture

My server uses: /usr/share/misc/file/magic.mime
How can I override PHP settings, do I have to edit my php.ini file or is it enough to add new value in .htaccess, if so, please help me to figure out, what value to add.
It supposes to be something like this: php_value mime_magic.magicfile "somedir\magic.mime"?

killes@www.drop.org’s picture

You need to edit php.ini.

mime_magic.magicfile "somedir/magic.mime"
--
Drupal services
My Drupal services

jsaints’s picture

I noticed here that mime magic functions have been deprecated:
http://us2.php.net/mime_magic

Only way I could get uploads to work was to comment out lines 150-156 and line 158 in the file.inc file.

anyone else have a solution?

killes@www.drop.org’s picture

This is due to a bug where this part of the code is called again after the file was moved thus causing an error.
--
Drupal services
My Drupal services

jonathan_hunt’s picture

I worked around it by installing the PECL fileinfo package, then replacing line 149 of file.inc with the following:

$info = new finfo(FILEINFO_MIME,"./magic");
$file->filemime = $info->file($file->filepath);

Seems to work ok so far.

perniila’s picture

If think it should be
mime_magic.magicfile = "somedir/magic.mime"

mbria’s picture

Add this section to your php.ini

[mime_magic]
mime_magic.magicfile = "/etc/magic"

works like a charm