Re: [PHP] Mime Magic functions - how standard are they?

2007-10-03 Thread mike
On 10/3/07, Dave M G <[EMAIL PROTECTED]> wrote:
> So, ultimately, what I'm wondering is, what should I be using in order
> to determine file MIME types that will be the most commonly installed on
> servers with PHP?

I wrote something that does system("file -iNr $file") which gives you
the application/mime-type output. the problem is that it was video
files, and a bunch of the microsoft video formats wind up showing up
as just generic binary data, just like executable files. I wound up
disabling it as I could not rely on it (I had to say "skip *.wmv from
processing" which rendered the whole point of this useless)

Depending on what you need the output for, that could work quite well.
Look into using file through the system() call. From the file types
you listed above I think it can identify them pretty well. Adjust the
options as needed. I decided to go that route instead of trying to
find a PECL or PEAR solution (or I checked and it didn't seem like a
good one was available at the time)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Mime Magic functions - how standard are they?

2007-10-03 Thread Dave M G

PHP List,

I would like to set up a function within my system that can test a file 
that a user has uploaded and determine what kind of file it is. My 
intention is to only handle a fairly small number of common file types*, 
so I don't think I need to build anything too robust.


Of course, I checked php.net, but was almost immediately confounded by 
what seems to be a transition from mime_content_type to Fileinfo. My 
confusion lies in the fact that on the one hand mime_content_type seems 
to be in the process of being depreciated, but at the same time, the 
Fileinfo functions seem to rely on PECL extensions which don't seem to 
be standard in every PHP installation.


At least, it seems like the PECL extensions are not present in my 
testing environment, which use default installation settings (via Ubuntu 
Feisty repositories).


When I tried to emulate the example on this page:
http://php.benscom.com/manual/en/function.finfo-open.php

... It gave me an error indicating the class "finfo" could not be found.

I'm trying to build a system that will hopefully be portable without 
anyone having to reconfigure PHP in any way to get it running.


So, ultimately, what I'm wondering is, what should I be using in order 
to determine file MIME types that will be the most commonly installed on 
servers with PHP?


Thank you for any advice.

* The file types I will test for are most likely to be the following:
.txt, .pdf, .png, .gif, .jpg, .mp3, .ogg, .doc, .odt, .zip, .gz... maybe 
that's it.


--
Dave M G
Zend Studio 5.5
Ubuntu 7.04

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php