title: php/jquery multiple file uploads
body: <p>I know there's quite a few topics on this already, and I've read quite a few of them, but to no avail. I have a form for uploading multiple files with descriptions. If the user needs more than one upload/description field, they can click a link to add another via jquery. The code for the form is:</p>
  
  <pre><code>&lt;form action="adm.php?mode=upload" method="post"&gt;
      &lt;input type="hidden" name="article_id" value="&lt;?php echo $article_id; ?&gt;" /&gt;
      &lt;input type="hidden" name="new_path" value="&lt;?php echo $new_path; ?&gt;" /&gt;
      &lt;div id="files"&gt;
          &lt;div id="file" class="row"&gt;
              &lt;input type="file" name="file[]" id="file" /&gt;&lt;br /&gt;
              Description:&lt;br /&gt;
              &lt;textarea name="desc[]" cols="50" rows="5"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="submit" name="submit" value="Submit" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;a href="#" id="add_upload"&gt;Add File&lt;/a&gt;
  </code></pre>
  
  <p>A clone of </p>
  
  <pre><code>&lt;div id="file" class="row"&gt;
      &lt;input type="file" name="file[]" id="file" /&gt;&lt;br /&gt;
      Description:&lt;br /&gt;
      &lt;textarea name="desc[]" cols="50" rows="5"&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>is appended to the files div when add_upload is clicked.</p>
  
  <p>I believe this is correct usage of <code>&lt;input type="file" name="file[]" id="file" /&gt;</code> according to php.net, however the listener script at adm.php?mode=upload never receives the $_FILES array upon submission:</p>
  
  <pre><code>case 'upload' :
      $path = request_var('new_path', '');
      $article_id = request_var('article_id', 0);
      $error = array();
      $messages = array();
  
  if(isset($_FILES['file']['tmp_name']))
  {
      // Number of uploaded files
      $num_files = count($_FILES['file']['tmp_name']);
  
      //create the directory if it doesn't exist already
      if(!is_dir($path))
      {
          mkdir($path);
      }
  
      /** loop through the array of files ***/
      for($i=0; $i &lt; $num_files;$i++)
      {
          // check if there is a file in the array
          if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
          {
              $messages[] = 'No file uploaded';
          }
          else
          {
              // copy the file to the specified dir
              if(@copy($_FILES['file']['tmp_name'][$i],$path.'/'.$_FILES['file']['name'][$i]))
              {
                  $messages[] = $_FILES['file']['name'][$i].' uploaded';
              }
              else
              {
                  /*** an error message ***/
                  $messages[] = 'Uploading '.$_FILES['file']['name'][$i].' Failed';
              }
          }
      }
  }
  else
  {
      $messages[] = 'No files set for upload??';
  }
  
  $err_msg = $messages;
  include($root_path.'pages/header.php');
  include($root_path.'pages/error.php');
  include($root_path.'pages/column.php');
  include($root_path.'pages/footer.php');
  exit;
  </code></pre>
  
  <p>break;</p>
  
  <p>I always get the "No files set for upload??" error because the files aren't being transferred. All of the other values are sent over POST and received with no problem. What am I doing wrong?</p>