File validation with Php

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

Post Reply
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

File validation with Php

Post by user___ »

Hi guys,
I have an upload form which accepts file which are the following types:
.exe,.swf,.avi.wmv.pdf.mpg, and mpeg
Is there any possible way to check whether these file types are real or not.

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: File validation with Php

Post by Chris Corbyn »

user___ wrote:Hi guys,
I have an upload form which accepts file which are the following types:
.exe,.swf,.avi.wmv.pdf.mpg, and mpeg
Is there any possible way to check whether these file types are real or not.

Thanks.
Reading the file extensions is a big no-no, but you sounds like you figured that :)

The .exe one will be tricky since that could probably be anything at all.

For the others, you can usually check the first few bytes in the file to see if they match the required headers. I'm not 100% though.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Actually, I did not figure it. I totally agree about the .exe file and it is already dropped from my list. Now, I would like to ask you whether you know how this header validation can be done.

Any kind of information is highly appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply