In our scripting sometimes we need to upload such documents , at that time there should be a validation for proper file.
For
example in your system suppose there is a field for image upload , that
is obvious in that field only image formats are allowed
(jpg,jpeg,png,gif etc.). At that time you have to give a validation on
that field.
In Php to find the extension and validation here is your code :
$image = $_FILES["file"]["name"]; // to fetch the file name
$n1=strripos($image,"."); // to find the last position of "."
$v1 =substr($image,$n1); // get the rest thing from last "."
$v1 = strtolower($v1); // convert into lowercase
if(($v1=='.jpg') || ($v1=='.png') || ($v1=='.jpeg') || ($v1=='.gif') ){}
else {
your message goes here
}
?>
enjoy.....
This comment has been removed by a blog administrator.
ReplyDelete