foreach $FILES create post how to

Got it, so I changed the name of the file input from thumbnail to thumbnail[]. Then I wrapped the above paste in a function and added this part at the top of the file and it works perfectly:

if ( $_FILES ) {
    $files = $_FILES['thumbnail'];
        foreach ($files['name'] as $key => $value) {
          if ($files['name'][$key]) {
          $file = array(
          'name' => $files['name'][$key],
          'type' => $files['type'][$key],
          'tmp_name' => $files['tmp_name'][$key],
          'error' => $files['error'][$key],
          'size' => $files['size'][$key]
          );

              $_FILES = array("" => $file);

              foreach ($_FILES as $file => $array) {
                      //call my function
                  create_var_product($file, $post_id);
              }
          }
    }
}