title: Codeigniter: Set upload file name in for loop
body: <p>I'm having problem with setting upload file names in for loop in Codeigniter, I want to add uploaded files (songs) to database and to some folder. I want to name them as song1, song2, song3... where number is song's ID in database. Here's my code:</p>
  
  <pre><code>   for ($i = 1; $i &lt; 201; $i++) {
  
          if (isset($_POST['name'.$i])) {
  
              $maxID = $this-&gt;Song_model-&gt;maxID();
              $maxID++;
              $config['file_name'] = "song".$maxID;
              $config['upload_path'] = "./assets/uploads/";
              $config['allowed_types'] = '*';
              $config['max_size'] = 0;
              $this-&gt;load-&gt;library('upload', $config);
  
              if ($this-&gt;upload-&gt;do_upload('file'.$i) == true) {
                  $data = array(
                      'IDArt' =&gt; $artistID,
                      'IDAlb' =&gt; $newAlbumId,
                      'songname' =&gt; $this-&gt;input-&gt;post('name'.$i),
                      'author' =&gt; $artistName,
                      'length' =&gt; $this-&gt;input-&gt;post('length'.$i),
                      'price' =&gt; $this-&gt;input-&gt;post('price'.$i)
                  );
                  $this-&gt;Song_model-&gt;persist($data);
              }
  
  
          }
  
      }
  </code></pre>
  
  <p>First song of many that i'm uploading get good name example: song11 (10 songs were in database before), but songs that are coming after this one, gets names song111, song 112.</p>
  
  <p><strong>Code segment:<br>
  $maxID = $this->Song_model->maxID();<br>
              $maxID++;</strong></p>
  
  <p>Gets me exact ID that i need to concatenate with "song" but, it seems I'm wrong with <strong>$config['file_name'] = "song".$maxID;</strong> this line</p>
  
  <p>Btw. song11, song111, song112 happens when file upload name is set to same value in this case "song11"</p>