title: PHP form with file-upload issue
body: <p>I'm working on a form to use with WordPress. What I have problems with is to allow only certain files to be uploaded and have a check for that. If a file is not allowed, an error-message should be displayed.</p>
  
  <p>Here is my form so far:</p>
  
  <pre><code>&lt;form method="post" id="campaignform" enctype="multipart/form-data" name="campaignform" onSubmit="return CheckForm();"&gt;
      Name: &lt;?php if(isset($empty_yourname)){ echo $empty_yourname;}?&gt;&lt;br /&gt;
      &lt;input type="text" id="yourname" name="yourname" value="&lt;?php if(isset($_POST['yourname'])){ echo $_POST['yourname'];}?&gt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      E-mail: &lt;?php if(isset($empty_email)){ echo $empty_email;} if(isset($invalid_email)){ echo $invalid_email;}?&gt;&lt;br /&gt;
      &lt;input type="text" id="email" name="email" value="&lt;?php if(isset($_POST['email'])){ echo $_POST['email'];}?&gt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      Telephone: &lt;?php if(isset($empty_telephone)){ echo $empty_telephone;}?&gt;&lt;br /&gt;
      &lt;input type="text" id="telephone" name="telephone" value="&lt;?php if(isset($_POST['telephone'])){ echo $_POST['telephone'];}?&gt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      Description: &lt;?php if(isset($empty_description)){ echo $empty_description;}?&gt;&lt;br /&gt;
      &lt;textarea id="description" name="description"&gt;&lt;?php if(isset($_POST['description'])){ echo htmlspecialchars($_POST['description']);}?&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      fileupload&lt;br /&gt;
      &lt;input type="file" id="file" name="file"&gt;&lt;br /&gt;
      &lt;input type="file" id="file2" name="file2"&gt;&lt;br /&gt;
      &lt;input type="file" id="file3" name="file3"&gt;&lt;br /&gt;
      &lt;input type="file" id="file4" name="file4"&gt;&lt;br /&gt;
      &lt;input type="file" id="file5" name="file5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;input type="checkbox" id="agreement" name="agreement"&gt;I accept the agreement. &lt;?php if(isset($empty_agreement)){ echo $empty_agreement;}?&gt;&lt;br /&gt;
      &lt;input type="submit" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And the PHP I have written so far (right now I'm only testing with one upload-field but this should be applied for all file fields):</p>
  
  <pre><code>&lt;?php
  /* on submit */
  if( $_SERVER['REQUEST_METHOD'] == 'POST') {
  
  /* check fields */
  if(is_array($_POST) &amp;&amp; empty($_POST['yourname']) OR empty($_POST['email']) OR empty($_POST['telephone']) OR empty($_POST['description']) OR empty($_POST['agreement']) OR !empty($_FILES['file']['name'])) {
  
  if (empty($_POST['yourname'])) {
      $empty_yourname = "Please enter your name.";
  }
  
  if (empty($_POST['email'])) {
      $empty_email = "Please enter your e-mail adress.";
  } else {
  
  $email = $_POST["email"];
  if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $invalid_email = "Invalid email format";
  }
  }
  
  if (empty($_POST['telephone'])) {
      $empty_telephone = "Please enter your telephone number.";
  }
  
  if (empty($_POST['description'])) {
      $empty_description = "Please enter a description.";
  }
  
  if (empty($_POST['agreement'])) {
      $empty_agreement = "You must accept the agreement.";
  }
  
  /* this check is not working properly */
  if (!empty($_FILES['file']['name'])) {
      $allowed =  array('gif','png','jpg');
      $filename = $_FILES['file']['name'];
      $ext = pathinfo($filename, PATHINFO_EXTENSION);
      if(!in_array($ext,$allowed)) {
          /* Output temporary error-message */
          echo 'Error';
      }
  }
  
  
  }
  
      /* We are successfull and post to DB */
      else {
  
          global $wpdb;
          $table = wp_verk1_campaign;
          $data = array(
              'contributorname'   =&gt; $_POST['yourname'],
              'email'             =&gt; $_POST['email'],
              'telephone'         =&gt; $_POST['telephone'],
              'description'       =&gt; $_POST['description'],
              'date'              =&gt; date('Y-m-d'),
              'time'              =&gt; date('H:i:s'),
              'upload'            =&gt; upload_user_file($_FILES['file']),
              'upload2'           =&gt; upload_user_file($_FILES['file2']),
              'upload3'           =&gt; upload_user_file($_FILES['file3']),
              'upload4'           =&gt; upload_user_file($_FILES['file4']),
              'upload5'           =&gt; upload_user_file($_FILES['file5'])
          );
          $format = array(
              '%s',
              '%s'
          );
  
          $success=$wpdb-&gt;insert( $table, $data, $format );
  
          if($success){
              echo 'data has been saved... ' ; 
          }
  
      }
  
      }
  ?&gt;
  </code></pre>
  
  <p>How can I make this work?</p>
  
  <p>Kind regards
  Johan</p>