Page 1 of 1

Finding MIME type

Posted: Thu Jan 29, 2009 3:17 pm
by ader
Hi!
I am trying to find the MIME type of a file, but the results I am getting are quite confusing. I am running Ubuntu 8.04.

The file with which I am testing is an OpenOffice writer file. My code is as follows:

Code: Select all

 
    $handle = finfo_open(FILEINFO_MIME);
    print(finfo_file($handle,$filename) . "\n");
 
This outputs "application/x-zip" which is clearly wrong or at least useless. If I, however, do a mimetype command in the console, the correct result is shown:

Code: Select all

application/vnd.oasis.opendocument.text
Running mimetype in debug mode, reveals the magic file used:

Code: Select all

Hashing magic from /usr/share/mime/magic
Trying now to let finfo use that magic file, however, returns an error:

Code: Select all

$handle = finfo_open(FILEINFO_MIME, '/usr/share/mime/magic');
Outputs:

Warning: finfo_open(): Failed to load magic database at '/usr/share/mime/magic'.

Has anyone run across this error before?

Yours sincerely
Rasmus

Re: Finding MIME type

Posted: Thu Jan 29, 2009 4:11 pm
by requinix
It's a bug. Try creating a copy of that file named "magic.mime" in the same place. Don't change the code.

Also,
ader wrote:This outputs "application/x-zip" which is clearly wrong or at least useless.
Wrong, no, but it is useless. OOo's files are actually ZIP files with a different extension. Try it yourself: rename the file to *.zip and open it up.
The new DOCX format (I think) works the same way.

Re: Finding MIME type

Posted: Fri Jan 30, 2009 1:13 am
by ader
Thanks, I tried that. Now I am getting a heap of errors like the following one:

/usr/share/mime/magic.mime, 980: Warning offset `[10:text/x-tex]' invalid

After that, I am again getting the message that it "Failed to load magic database at '/usr/share/mime/magic'."

Any other ideas?

Rasmus

Re: Finding MIME type

Posted: Fri Jan 30, 2009 2:54 am
by requinix
Then finfo doesn't like that file. See if there's another magic file on the system somewhere, or maybe if your distro has a different version.