title: Agile Uploader Wordpress implementation
body: <p>I'm trying to implement a front page Wordpress uploader which gives the user the possibility to upload an image from a Wordpress page and also resizes images before upload. I found Agile Uploader. The uploader is in a form. </p>
  
  <p>The problem is when I click the submit button in the form to send the data, all fields are stored in a post, but the images not.</p>
  
  <p>Here is the code for my upload page:</p>
  
  <pre><code>&lt;form id="submitForm" action="&lt;?php echo get_permalink(); ?&gt;" method="post" enctype="multipart/form-data" onsubmit="return ray.ajax()"&gt;
  &lt;!-- upload photos --&gt;
  
    &lt;div style="float:left;width:410px; height:246px;"&gt;
      &lt;div id="multiple"&gt;&lt;/div&gt;
    &lt;/div&gt;
  
    &lt;script type="text/javascript"&gt;
      jQuery('#multiple').agileUploader({
        formId: 'submitForm',
        flashVars: {
          file_post_var: 'attachment',
          firebug: false,
          form_action: '',
          file_limit: 15,
          max_post_size: (1000 * 1024)
        }
      }); 
    &lt;/script&gt;
  
    &lt;/div&gt;   &lt;!-- end - upload photos --&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and the code for Wordpress upload (it`s in the same file)</p>
  
  <pre><code>/* upload photos */
  if ($post_error == false) {
  
    /* required files */
    require_once(ABSPATH . "wp-admin" . '/includes/image.php');
    require_once(ABSPATH . "wp-admin" . '/includes/file.php');
    require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  
    $files = $_FILES['attachment'];
  
    if ($files) { 
  
      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("attachment" =&gt; $file);
        //$_FILES = array_reverse($_FILES);
        foreach ($_FILES as $file =&gt; $array) {                                  
          $attach_id = media_handle_upload( $file, $ad_id, array(), array( 'test_form' =&gt; false ) );
          if ($attach_id &lt; 0) { $post_error = true;
        }
      }
    }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>