[eluser]Unknown[/eluser]
Hello!
I am just a beginner in codeigniter, and also not very experienced in PHP either. I just like to play with something to learn and CI really gives a lot of opportunities for learners like me!
I just faced a problem uploading multiple files from the input file field with same name.
My html forms has some fields like this .
Code:
<input type="text" name="question[]" value="b" />
<input type="file" name="explanationvid[]" value="w" />
an array of explanationvids. Array is required as there are no fixed number of files. User click a button "add section" to dynamically generate the input field.
Now i can work with
Code:
$this->input->post('question', TRUE);
which fetches the entire array named question from post
but how do i upload the files in the field named explanationvid[]
i am trying to do something like this-
Code:
for ($sidx = 0; $sidx < sizeof($lessonVidData['explanationvid']); $sidx++) {
....
....
....
$filename = 'e'.$this->session->userdata('username').now();
$config['upload_path'] = './files/exp/';
$config['allowed_types'] = 'flv';
$config['file_name'] = $filename;
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$sectionData[$sidx]['explanation']= $filename;
if (!$this->upload->do_upload('explanationvid')) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
...
...
...
}
but it doesnt work, i know it shouldnt as i believe do_upload() expects name of a single field not an array.
Please tell me how i can tell do_upload() something like -
Code:
$this->upload->do_upload('explanationvid['.$sidx.']')
or
Code:
$this->upload->do_upload('explanationvid[0]')
where $sidx is the index of the array
i prefer this 1 by 1 upload as i also need to do some database insertion for each upload