Re: Checking file type when uploading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2010-09-18 at 11:21 +0200, Peter Lind wrote:

> On 17 September 2010 23:25, Jim Lucas <lists@xxxxxxxxx> wrote:
> > Catherine Madsen wrote:
> >> Hi!
> >>
> >> I have created a form following the PHP manual to upload files and need
> >> to restrict the upload to only PDF.  How do I check the file type
> >> ($_FILES['userfile']['type']?) and where: on the form page or on the
> >> validation page?  I want to be able to tell the users that their file
> >> doesn't have the right format.  Thank you very much for your help!
> >>
> 
> You need to use something like http://www.fpdf.org/ to try and
> actually open the uploaded file - anyone can fake an extension.
> 
> Regards
> Peter
> 
> -- 
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> BeWelcome/Couchsurfing: Fake51
> Twitter: http://twitter.com/kafe15
> </hype>
> 


An exec() call to the 'file' command (assuming you're on a Linux server)
should give you back the correct file type as well. I just tested mine
with file-5.03 on a mis-named file and it correctly detected it. That's
not to say a carefully crafted file couldn't trick it, but it might be
good as a general checker where it would be a lot of hassle trying to
check every single file type by opening it up.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux