Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check image extension before uploading a image ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 152
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: