login | register
Sat 06 of Sep, 2008 (21:47 UTC)

bitweaver - Web Application Framework and CMS

Web Application Framework and CMS

     
Thread UnlockedNon Sticky Thread

Incorrect mime_type stored in liberty_files

Chris Stone
Joined: 18 Jul 2008
Reply to this PostReply with Quote to this Post

Incorrect mime_type stored in liberty_files

Posted: Thu 24 of Jul, 2008 (13:49 UTC),
When I download files such as PPT, XLS etc. they are all identified as application/msword for some reason. This is the value stored for mime_type in liberty_files.

If I look at the file details /treasury/file/ the ICON is correctly selected but next to Filename is (application/msword).

I've traunched through the code but it's really hard to tell where this is happening.

If I look at lookupMimeType this seems to work when passed an XLS or PPT extension and returns the correct mime_type - so I really don't know where this is happening.
spiderr
Avatar
Joined: 08 Feb 2004
Reply to this PostReply with Quote to this Post

Re: Incorrect mime_type stored in liberty_files

Posted: Thu 24 of Jul, 2008 (14:51 UTC),
What is the link you are using to download the files? Is it a direct link to the .xls in the storage/ directory etc.? If so, it is likely that your webserver is "helping you out" here.
Chris Stone
Joined: 18 Jul 2008
Reply to this PostReply with Quote to this Post

Re: Incorrect mime_type stored in liberty_files

Posted: Thu 24 of Jul, 2008 (16:45 UTC), Last modification by:Chris Stone, Thu 24 of Jul, 2008 (17:12 UTC)
I think I found (part of the issue at least):

If I comment out the escapeshell arg bit (as below) the mime type is then correct based on extension, i.e. it doesn't do a 'file ....' on the file (which returns:
'Microsoft Office Application' or 'application/msword' if I use 'file -bi' for each of PPT, XLS and DOC!)

Hmmm... must be some system issue or magic going wrong...

kernel/BitSystem.php:
  function verifyMimeType( $pFile ) {
                $mime = NULL;
                if( file_exists( $pFile ) ) {
                        if( function_exists( 'finfo_open' ) ) {
                                $finfo = finfo_open( FILEINFO_MIME );
                                $mime = finfo_file( $finfo, $pFile );
                                finfo_close( $finfo );
                        } /*else {
                                if (functionEnabled ("escapeshellarg") && functionEnabled ("exec"))
                                        $mime = exec( trim( 'file -bi ' . escapeshellarg ( $pFile ) ) );
                        }*/
                        if( empty( $mime ) ) {
                                $mime = $this->lookupMimeType( substr( $pFile, strrpos( $pFile, '.' ) + 1 ) );
                        }
                        if( $len = strpos( $mime, ';' ) || $len = strpos( $mime, ';' ) ) {
                                $mime = substr( $mime, 0, $len );
                        }
                }
                return $mime;
}

Chris Stone
Joined: 18 Jul 2008
Reply to this PostReply with Quote to this Post

Re: Incorrect mime_type stored in liberty_files

Posted: Thu 24 of Jul, 2008 (17:18 UTC),
OK - It looks like magic on my RH ES4 OS.

/usr/share/file/magic.* is returning the application/msword for file -bi

Is there some configuration option that I could use, like disabling 'escapeshellarg'? Not sure what else that would affect...

Thanks,
C.
Chris Stone
Joined: 18 Jul 2008
Reply to this PostReply with Quote to this Post

Re: Incorrect mime_type stored in liberty_files

Posted: Thu 24 of Jul, 2008 (21:42 UTC), Last modification by:Chris Stone, Thu 24 of Jul, 2008 (21:44 UTC)
Better solution in the end was to modify my magic (/usr/share/file/magic.mime):

0 string \376\067\0\043 application/msword
#0 string \320\317\021\340\241\261 application/msword
0 string \333\245-\0\0\0 application/msword

then recompile with: file -C

Problem went away then.... seems like it should affect quite a few people though.
Lester Caine
Joined: 24 Apr 2004
Reply to this PostReply with Quote to this Post

Re: Incorrect mime_type stored in liberty_files

Posted: Fri 25 of Jul, 2008 (03:43 UTC),
The widows copy of magic.mime is fun as well. The problem here IS the php end getting things wrong. And we have to hard code the location in windows to get it to work at all.