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:
for ($i = 1; $i < 201; $i++) {
if (isset($_POST['name'.$i])) {
$maxID = $this->Song_model->maxID();
$maxID++;
$config['file_name'] = "song".$maxID;
$config['upload_path'] = "./assets/uploads/";
$config['allowed_types'] = '*';
$config['max_size'] = 0;
$this->load->library('upload', $config);
if ($this->upload->do_upload('file'.$i) == true) {
$data = array(
'IDArt' => $artistID,
'IDAlb' => $newAlbumId,
'songname' => $this->input->post('name'.$i),
'author' => $artistName,
'length' => $this->input->post('length'.$i),
'price' => $this->input->post('price'.$i)
);
$this->Song_model->persist($data);
}
}
}
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.
Code segment:
$maxID = $this->Song_model->maxID();
$maxID++;
Gets me exact ID that i need to concatenate with "song" but, it seems I'm wrong with $config['file_name'] = "song".$maxID; this line
Btw. song11, song111, song112 happens when file upload name is set to same value in this case "song11"