[RCD] mime problem - excel file as text/plain

till klimpong at gmail.com
Wed Mar 4 17:56:51 CET 2009


On Wed, Mar 4, 2009 at 4:56 PM, chasd <chasd at silveroaks.com> wrote:
>> Otherwise I wouldn't know why
>> it doesn't work while a simple file does. They should use the same
>> magic database in the end.
>
> First, trusting the mime-type from the client is very dangerous.
>
> On Fedora, the php-pear-Fileinfo package uses the same magic file
> that the command line file command uses.
> If you compile the fileinfo extension separately, you might be using
> a different magic file, which might provide inconsistent results.
> I have seen /usr/share/misc/magic ( default for fileinfo upstream )
> and /usr/share/file/magic ( default for Fedora ).
>
> You also need to use the same flags or options.
> Using the PHP fileinfo functions, there are options you pass
> ( FILEINFO_MIME ) in order to get the output you want.
> Using the file command, there are flags you pass ( -i ) in order to
> get the output you want.
>
> The defaults are different between the two.
>
> For example, these options should give the same between <?php
> finfo_file() ?> and file from the command line -
>
> file -biLz filename
> finfo_file($finfo,"filename",1046)
>
> You need to add the integer values of the FILEINFO_* options
>
> -b is the default for finfo_file()
> -i == FILEINFO_MIME or 1040
> -L == FILEINFO_SYMLINK or 2
> -z == FILEINFO_COMPRESS or 4
>
> -k == FILEINFO_CONTINUE or 32, which is mutually exclusive of
> FILEINFO_MIME
> That is, you can't use FILEINFO_CONTINUE and FILEINFO_MIME together,
> is is either one of the other.
> Sometimes using FILEINFO_CONTINUE and parsing that string gives you
> more information than FILEINFO_MIME does, but that parsing is harder
> and more complicated.
>
> if
> finfo_file($finfo,"filename",1040)
> returns a gzip or zip mime-type, you could then do
>
> finfo_file($finfo,"filename",1044)
>
> to see what type of data is inside that compressed file.
>
> HTH
>
>

Maybe we need a wiki page.

@Charles, would you be so kind and start on one? I'd contribute some
findings as well.

This also sounds like a great opportunity for a couple unit tests.
I'll make myself a mental note for that.

Till
_______________________________________________
List info: http://lists.roundcube.net/dev/



More information about the Dev mailing list