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.
File validation with Php
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: File validation with Php
Reading the file extensions is a big no-no, but you sounds like you figured thatuser___ 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.
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.
Reply
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.
Any kind of information is highly appreciated.
Take a look at http://php.net/finfo_file and http://php.net/mime_content_type (deprecated)