title: Illegal offset type when uploading a file PHP
body: <p>All,
  I'm using this input field:</p>
  
  <pre><code>&lt;input type="file" name="image_to_upload_image" accept="image/*"&gt;
  </code></pre>
  
  <p>I'm then trying to process the file upload with the following code:</p>
  
  <pre><code>if ( $_FILES["image_to_upload_image"] ) { 
      echo "it will try and upload";
      $file = $_FILES["image_to_upload_image"];
      print_r($file);
      $newupload = bmt_handle_attachment_new_post($file,$post_id); 
      echo "The newupload is: ".$newupload;
      set_post_thumbnail( $post_id, $newupload );
  }
  </code></pre>
  
  <p>Which calls the following function:</p>
  
  <pre><code>function bmt_handle_attachment_new_post($file_handler,$post_id,$set_thu=false) {
      // check to make sure its a successful upload
      if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
  
      require_once(ABSPATH . "wp-admin" . '/includes/image.php');
      require_once(ABSPATH . "wp-admin" . '/includes/file.php');
      require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  
      $attachment_id = media_handle_upload( $file_handler, $post_id );
  
      if ( is_wp_error( $attachment_id ) ) {
          // There was an error uploading the image.
      } else {
          // The image was uploaded successfully!
      }
  
       // If you want to set a featured image from your uploads. 
      return $attachment_id;
  }
  </code></pre>
  
  <p>I'm doing the same thing as this example:
  <a href="http://codex.wordpress.org/Function_Reference/media_handle_upload" rel="nofollow">http://codex.wordpress.org/Function_Reference/media_handle_upload</a> </p>
  
  <p>Why is it saying illegal offset type? </p>
  
  <p>UPDATE: I have another form that has the same input field except it handles multiple file uploads:</p>
  
  <pre><code>&lt;input type="file" name="kv_multiple_attachments[]"  multiple="multiple" &gt;
  </code></pre>
  
  <p>If I then pass it to the following form handler:</p>
  
  <pre><code>if ( $_FILES ) { 
      $files = $_FILES["kv_multiple_attachments"];
      $gallery_id = $_POST['gallery_for_upload'];  
      foreach ($files['name'] as $key =&gt; $value) {            
              if ($files['name'][$key]) { 
                  $file = array( 
                      'name' =&gt; $files['name'][$key],
                      'type' =&gt; $files['type'][$key], 
                      'tmp_name' =&gt; $files['tmp_name'][$key], 
                      'error' =&gt; $files['error'][$key],
                      'size' =&gt; $files['size'][$key]
                  ); 
                  $_FILES = array ("kv_multiple_attachments" =&gt; $file); 
                  foreach ($_FILES as $file =&gt; $array) {                          
                      $newupload = bmt_handle_attachment($file,$pid,$gallery_id); 
                          //$thumb_url = wp_get_attachment_thumb_url( $newupload );
                          //echo "&lt;img src=".$thumb_url."&gt;";
                  }
              } 
          } 
      }
  </code></pre>
  
  <p>Then use the same processing function:</p>
  
  <pre><code>function bmt_handle_attachment($file_handler,$post_id,$gallery_id,$set_thu=false) {
  // check to make sure its a successful upload
  if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
  
  require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  
  $attachment_id = media_handle_upload( $file_handler, $post_id );
  update_post_meta( $attachment_id, 'bmt_gallery_id', $gallery_id );
  
   // If you want to set a featured image frmo your uploads. 
  return $attachment_id;
  }
  </code></pre>
  
  <p>The files are uploaded without an issue.</p>