using explode to determin filetypes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?: I just tested it on a windows xp system. The necessary code is included in php (or the mime extension) and has not much to do with the underlaying system. The apache installation gets you a copy of mime.magic usable with php.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

IIS installs won't have it. How many Windows servers run Apache? I'd say not many. Hell, my local Apache install doesn't even respond to it.

But this choice is for my project(s). It's fine for anyone else. :)

edit: I just realized what I was thinking of before with the magic file, I was thinking of the types file. Der! Turns out I've got a corrupt (blank) magic file too. meh.

Thinking about it, it shouldn't be hard to build a simple function that performs the same actions as mime_content_type() independent of Apache (if PHP doesn't do it in some fashion already.) Unless my cold is much worse than I think it is, I don't recall a facility that does this on IIS that PHP will use. hmmm...
Last edited by feyd on Thu Jan 04, 2007 12:48 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

feyd wrote:IIS installs won't have it.
I don't see the point. IIS installs don't have php either and yet people are using it.
feyd wrote:Hell, my local Apache install doesn't even respond to it.
it's the file conf/magic.
Btw: php-5.2.0-Win32.zip from php.net ships with the file extras/mime.magic
feyd wrote:But this choice is for my project(s). It's fine for anyone else. :)
What do you use to determine the content type of a file?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

In case you missed it, I've edited a bit into my last post...

Anyways, I basically do the same as mime_content_type() does except I look it a little deeper and verify a lot more information than strictly the header tag.

It can require more work in the long run (like when the file specifications change) but I prefer to be pretty safe over loose and free. :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

feyd: just curious, why don't you use some sort of WAMP package like Uniform Server?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Because I'm not lazy enough to use an installer package.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

.... :?:

Uniform Server has no installer, you just run a batch file to start apache (and optionally mysql).

I like it because it's completely portable, completely configurable, and it's similar to most production servers.

You can drop-in a replacement for php, apache, etc... no problems.

I don't mean to bash IIS, I just wanted to know if there was a reason you used it instead.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Kieran Huggins wrote:.... :?:

Uniform Server has no installer, you just run a batch file to start apache (and optionally mysql).

I like it because it's completely portable, completely configurable, and it's similar to most production servers.

You can drop-in a replacement for php, apache, etc... no problems.

I don't mean to bash IIS, I just wanted to know if there was a reason you used it instead.
I don't use IIS personally -- I run Apache -- But my projects tend to be run on a variety of servers, including IIS. This removes things would normally be available under Apache, let alone Unix.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Again - only for clarity for someone who didn't read the whole thread - the mime.magic file ships with php, mime_content_type does not need apache or an unix environment and it does examine parts of the contents of the file to test.
Of course, if you need a more in-depth-test you will need something else. But to assure the file is not of another content type mime.magic is feasible. Testing the filename or parts of it is insufficient.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Here's hoping that they have the ability to alter the php.ini or the host has done so already to mark the path to the mime file. :)
Post Reply