Incorrect mime_type stored in liberty_files

Chris
Joined: 18 Jul 2008

Incorrect mime_type stored in liberty_files

Posted:24 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/<id> 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.</id>
spiderr
Profile Picture
Joined: 08 Feb 2004

Re: Incorrect mime_type stored in liberty_files

Posted:24 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
Joined: 18 Jul 2008

Re: Incorrect mime_type stored in liberty_files

Posted:24 Jul 2008 (16:45 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:

<?php
  
function verifyMimeType$pFile ) {
                
$mime NULL;
                if( 
file_exists$pFile ) ) {
                        if( 
function_exists'finfo_open' ) ) {
                                
$finfo finfo_openFILEINFO_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->lookupMimeTypesubstr$pFilestrrpos$pFile'.' ) + ) );
                        }
                        if( 
$len strpos$mime';' ) || $len strpos$mime';' ) ) {
                                
$mime substr$mime0$len );
                        }
                }
                return 
$mime;
}
?>

Chris
Joined: 18 Jul 2008

Re: Incorrect mime_type stored in liberty_files

Posted:24 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
Joined: 18 Jul 2008

Re: Incorrect mime_type stored in liberty_files

Posted:24 Jul 2008 (21:42 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

Re: Incorrect mime_type stored in liberty_files

Posted:25 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.
Stephan Borg
Joined: 15 Feb 2004

Re: Incorrect mime_type stored in liberty_files

Posted:01 Jul 2009 (10:34 UTC)
Was a fix ever found for this issue? I'm having the same problem. Commenting out the code works for me too, but not sure if thats the right thing to do.
Lester Caine
Joined: 24 Apr 2004

Re: Incorrect mime_type stored in liberty_files

Posted:01 Jul 2009 (19:56 UTC)
In theory the problem has been fixed in PHP5.3 - but since there is still a lot of libraries that still need to be updated - testing is still a major problem.
As long as on windows systems, the correct path to magic is set in config_inc.php - as pointed out in the installer - then windows works OK.
  Page 1 of 1  1