title: Rename uploaded files
body: <p>I am uploading files via php.
  The amount of files can be uploaded is determined by a value which is stored in database. So let's say, this value is 3, than my code show three html file input. This is working. I could also rename one file too. working extension filter, and size restrictions.. But when I tried to do this with more than one, I stacked... The new name should be the 'number of list element'-'base filename'.
  Example:</p>
  <p>
  1-thisisanimage.jpg<br>
  2-anotherimage.jpg<br>
  3-andthisalso.jpg
  </p>
  <p>I tried with foreach but I think I over-complicated. I also tried different scripts from the internet but none of them really what I just cannot do this. Anybody? :)</p>
  <h3>EDIT: added the part of my code</h3>
  <pre><code>if (!file_exists(&quot;uploads/&quot;.$date.&quot;-&quot;.$email.&quot;-vid-&quot;.$videoID)) {
      mkdir(&quot;uploads/&quot;.$date.&quot;-&quot;.$email.&quot;-vid-&quot;.$videoID.&quot;/&quot;, 0777, true);
      }
  
      $imagecounter = 0;
          $_FILES[&quot;file&quot;] = array();
      foreach ($_FILES[&quot;file&quot;] as $file) {
          $imagecounter++;
          
              
          $filename = $_FILES[&quot;file&quot;][&quot;name&quot;];
          $file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
          $file_ext = substr($filename, strripos($filename, '.')); // get file name
          $filesize = $_FILES[&quot;file&quot;][&quot;size&quot;];
          $allowed_file_types = array('.jpg','.jpeg','.png','.gif');  
       
          if (in_array($file_ext,$allowed_file_types) &amp;&amp; ($filesize &lt; 200000))
          {   
              // Rename file
              $newfilename = &quot;$imagecounter-&quot;.$file_basename . $file_ext;
              if (file_exists(&quot;uploads/&quot;.$date.&quot;-&quot;.$email.&quot;-vid-&quot;.$videoID.&quot;/&quot; . $newfilename))
              {
                  // file already exists error
                  echo &quot;You have already uploaded this file.&quot;;
              }
              else
              {       
                  move_uploaded_file($_FILES[&quot;file&quot;][&quot;tmp_name&quot;], &quot;uploads/&quot;.$date.&quot;-&quot;.$email.&quot;-vid-&quot;.$videoID.&quot;/&quot; . $newfilename);
                  echo &quot;File uploaded successfully.&quot;;     
              }
          }
  </code></pre>