PHP Classes

File type falidation

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  File type falidation  >  (Un) Subscribe thread alerts  
Subject:File type falidation
Summary:Validating the type of a submited file ( ex gif or jpg )
Messages:4
Author:mlmarius
Date:2007-06-06 16:27:49
Update:2007-06-07 15:25:35
 

  1. File type falidation   Reply   Report abuse  
Picture of mlmarius mlmarius - 2007-06-06 16:27:49
is there any way of checking the types of files that the users try to submit ? ( i have included only the forms.php )

  2. Re: File type falidation   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-06-06 23:06:01 - In reply to message 1 from mlmarius
You could check the file names or use the ACCEPT parameter to specify the accepted MIME types. But that would not be a very reliable form of validation because the users could name a file with a certain extension that does not match the content.

On the browser side it is not possible to validate the file contents because Javascript is not allowed to read files.

On the server side, you can read the files and check if their real type is what you expect but that forms class does not do that because it can be very complicated. Maybe that is a good idea to implement with a separate custom plug-in class.

  3. Re: File type falidation   Reply   Report abuse  
Picture of mlmarius mlmarius - 2007-06-07 08:25:53 - In reply to message 2 from Manuel Lemos
so i just define my own php function and then add a server side validation function for the respective file input right ?

  4. Re: File type falidation   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-06-07 15:25:35 - In reply to message 3 from mlmarius
Yes, that is probably the best way to make sure the files are of the type you expect.