title: dynamic number of file upload - PHP
body: <p>I'm creating a page when user can enter how many files he want to upload then that page is rendered again with a form, after submission to another page the files are uploaded.<br>
  But i'm receiving an error [if i upload 1 file, else the problem is userfile[limit-1]]<br>
  <code>Notice: Undefined index: userfile0 in E:\wamp\www\uploader\uploader.php on line 10</code></p>
  
  <p>I'm pasting here my code
  <strong>index.php</strong>  </p>
  
  <pre><code>&lt;html&gt;
  &lt;?php
  if (isset($_POST['num']) &amp;&amp; !empty($_POST['num']))
  {
  ?&gt;
  &lt;form name="uploader" action="uploader.php" method="post"&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td&gt;Title&lt;/td&gt;&lt;td&gt;Select File&lt;/td&gt;&lt;td&gt;Description&lt;/td&gt;&lt;/tr&gt;
  &lt;input type="text" name="number" value="&lt;?php echo $_POST['num']; ?&gt;"/&gt;
  &lt;?php
  for ($i=0;$i&lt;$_POST['num'];$i++)
   echo '&lt;tr&gt;&lt;td&gt;&lt;input type="text" name="title'.$i.'"/&gt;&lt;/td&gt;
             &lt;td&gt;&lt;input type="file" id="userfile'.$i.'" name="userfile'.$i.'" size="30"&gt;&lt;/td&gt;
             &lt;td&gt;&lt;textarea name="desc'.$i.'" rows="4"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;';
  ?&gt;
  &lt;/table&gt;
  &lt;input type="submit" name="b" value="Submit"/&gt;
  &lt;/form&gt;
  &lt;?php
  }
  else
  {
  ?&gt;
  &lt;form name="form" method="post"&gt;
  How many files to upload ? &lt;input type="text" name="num" value="1"/&gt;
  &lt;input type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  &lt;?php
  }
  ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>uploader.php</strong></p>
  
  <pre><code>&lt;?php
  if (isset($_POST['number']))
  {
   for ($slot = 0; $slot &lt; $_POST['number']; $slot++)
   {
    $title = $_POST["title$slot"];
    $desc = $_POST["desc$slot"];
    if (move_uploaded_file($_FILES["userfile$slot"]['tmp_name'],$_FILES["userfile$slot"]['name']))
     echo $name.' file Uploaded !';
    else
     echo ' file not Uploaded ! ';
   }
  }
  ?&gt;
  </code></pre>
  
  <p><code>Edit</code><br>
  SQL code removed</p>