Incorrect mime_type stored in liberty_files
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>
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>
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...
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...
<?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;
}
?>
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.
/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.
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.
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.
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.
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