There are many way to check image extension before uploading.
But "in_array()" function it is very useful way to check image extension when you are uploading a lots of extensions to validate.
if the "in_array()" function fails, this mean condition is failed then.
You can see below example that how you can check image extension before uploading a image ?
<?php
//here $image_type is a array variable
$image_type = array('gif','jpg','jpeg','png');
$upload_image = 'newimage.png';
// here Utilizing strtolower to surmount case sensitive
$extension = strtolower(pathinfo($upload_image, PATHINFO_EXTENSION));
//here call in_array() to check image extension
if (in_array($extension, $image_type))
{
echo "image extension is valid";
}
else
{
echo 'image extension not valid';
}
?>
Output will come following:
when image extension exist in "in_array()" function
then, result will be as shown below
image extension is valid
otherwise, result will be
image extension not valid
0 Comment(s)