Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to restrict the file type to be upload using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 149
    Comment on it

    Hello Reader's If you are uploading the attachments with only selected file types then you have to use inarray function. Let's see the example as below:-

    Put the allowed types in an array and use in_array().

    $file_type = $_FILES['foreign_character_upload']['type']; //returns the mimetype
    
    $allowed = array("image/jpeg", "image/gif", "application/pdf");
    if(!in_array($file_type, $allowed)) {
      $error_message = 'Only jpg, gif, and pdf files are allowed.';
      $error = 'yes';
    }
    

    Now only the files with .jpeg or gif or pdf will only upload.

 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: