php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33028 mime_content_type returns inaccurate Office content types
Submitted: 2005-05-13 20:12 UTC Modified: 2005-05-15 03:17 UTC
From: matt at kanchi dot org Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.10 OS: OS X
Private report: No CVE-ID: None
 [2005-05-13 20:12 UTC] matt at kanchi dot org
Description:
------------
Certain Office files do not return an accurate MIME content type with mime_content_type.  Excel and Powerpoint, for example, return an application/msword type, while Access returns text/plain.  Images, text, and Word files return correctly.  These files were generated in Office 2002 for Windows.

Configuration options:

--with-mime-magic

From php.ini:

mime_magic
mime_magic support => enabled
Directive => Local Value => Master Value
mime_magic.magicfile => /usr/share/file/magic.mime => /usr/share/file/magic.mime

Reproduce code:
---------------
mime_content_type("/some/path/to/xls-file");
mime_content_type("/some/path/to/ppt-file");
mime_content_type("/some/path/to/mdb-file");

Expected result:
----------------
application/msexcel
application/mspowerpoint
application/msaccess

Or some variation (vnd, x-, etc.).

Actual result:
--------------
application/msword
application/msword
text/plain

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-13 21:37 UTC] tony2001@php.net
Does this work: `file /path/to/file.ppt` ?
 [2005-05-13 22:37 UTC] matt at kanchi dot org
Do you mean mime_content_type("file /path/to/file")?  If so, that returns the error, "mime_magic: invalid mode 0156130."
 [2005-05-13 23:33 UTC] tony2001@php.net
No, I meant running this command in console.
 [2005-05-14 00:50 UTC] matt at kanchi dot org
Gotcha.  It returns:

(filename): Microsoft Office Document
 [2005-05-14 00:55 UTC] matt at kanchi dot org
In case you meant "file -i /path/to/file.ppt", that returns the same as mime_content_type does (in my case) for those files.  -k returns only one result.
 [2005-05-14 11:02 UTC] tony2001@php.net
So, the bug is not in PHP, but in your mime.magic file.
No PHP bug -> bogus.
 [2005-05-15 03:17 UTC] matt at kanchi dot org
Well, I upgraded file to 4.13 (the latest version), and the MIME magic file may be more complicated but it returns the same thing.  Since PHP relies on this file, wouldn't it make sense to check the extension against what the MIME magic file returns to determine if it's correct?  I would think a warning would at least be warranted in the documentation until it's resolved.  Who knows, maybe I'm the only one who's having this problem.

Anyway, I guess I'll just manually handle Office extensions or something.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 29 06:01:30 2024 UTC