file.inc from version 1.52 uses mime_content_type() in file_check_upload() to determinate the uploaded files' mime type. As result drupal can not recognize flash (.swf) files in Fedora Core 3, 4, CentOS 4.2 and maybe others as there is no entry in /usr/share/file/magic.mime for flash. This breaks at least banner.module in 4.6.5 (as would in 4.7.0-beta3 too) resulting in wrong mime type and file extension.

For me getimagesize() in the attached patch fixes the problem.

* maybe node/16142 is related to this one.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr700’s picture

Title: file.inc gives bad mimetype to uploaded flash files (mime_content_type) » file.inc gives bad mimetype to uploaded flash/png files (mime_content_type)
Priority: Normal » Critical

I also have similar problem with drupal-4.6.5 - can not upload user picture (avatar). The message in the watchdog says:

For /tmp/XXXXX the system thinks its MIME type is text/plain while the user has given image/png for MIME type
For /tmp/XXXXX the system thinks its MIME type is while the user has given image/png for MIME type

and the page says:

File copy failed: source file does not exist.
Failed to upload the picture image; the avatars directory does not exist.

The 'avatars' directory exists and after applying the attached here patch it works fine. The file was in png format (gif and jpeg work fine). I used Fedora Core 4 (mysql 4.1 and php 5).

PP: Should I fill new but report for 4.6.5 and cvs?

mr700’s picture

Status: Active » Needs review
FileSize
10.01 KB

Here's a small test suite with php script and 3 images that can be used to verify this problem. My results are:

+----------------------------------+-------------------+-------------------+
| File named                       | mime_content_type |      getimagesize |
+----------------------------------+-------------------+-------------------+
|                          php.gif |         image/gif |         image/gif |
|                  blank-ico64.png |        text/plain |         image/png |
|                         dcat.jpg |        image/jpeg |        image/jpeg |
+----------------------------------+-------------------+-------------------+

Just me?

Egon Bianchet’s picture

On Ubuntu breezy:

+----------------------------------+-------------------+-------------------+
| File named                       | mime_content_type |      getimagesize |
+----------------------------------+-------------------+-------------------+
|                  blank-ico64.png |         image/png |         image/png |
|                         dcat.jpg |        image/jpeg |        image/jpeg |
|                          php.gif |         image/gif |         image/gif |
+----------------------------------+-------------------+-------------------+
mr700’s picture

Hmm, strange. I did some more tests on all linux boxes I have. Here are the results:

+---------------+-------------+------------+-------------------+--------------+
|               |             |            | mime_content_type | getimagesize |
| distro        |   apache    |     php    +-------------------+------+-------+
|               |             |            |   png   |  flash  |  png | flash |
+---------------+-------------+------------+---------+---------+------+-------+
| CentOS 3.6    |             |            |   yes   |    no   |  yes |  yes  |
| CentOS 4.2    | 2.0.52-22   | 4.3.9-3.9  |   yes   |    no   |  yes |  yes  |
| Fedora Core 1 | 2.0.51      | 4.3.11     |   N/A*  |   N/A*  |  yes |  yes  |
| Fedora Core 2 | 2.0.51      | 4.3.11-1   |   N/A*  |   N/A*  |  yes |  yes  |
| Fedora Core 3 | 2.0.53-3.3  | 4.3.11-2.8 |   yes   |    no   |  yes |  yes  |
| Fedora Core 4 | 2.0.54-10.2 | 5.0.5-2.1  |    no   |    no   |  yes |  yes  |
+---------------+-------------+------------+---------+---------+------+-------+
* N/A - function not available

In short: everywhere flash gets wrong MIME type ('text/plain'), for "Fedora Core 4" png also gets 'text/plain'. The problem with png files is clearly a FC4's bug (I reported this in bugzilla - bug # 177926).

The main problem I have are flash files (with banner.module). Can you please also test a flash file?

BTW: mime_content_type() returns 'text/plain' where it does not recognize the file, getimagesize() returns nothing.

chx’s picture

Status: Needs review » Closed (duplicate)

http://drupal.org/node/43220 will solve this & many more.