Welcome Guest, Not a member yet? Register   Sign In
Problem uploading multiple files from the input file field with same name
#1

[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
#2

[eluser]dnc[/eluser]
Please check this post :
Multiple File Upload


and keep us up to to date on your progess!
#3

[eluser]Unknown[/eluser]
[quote author="dnc" date="1339047424"]Please check this post :
Multiple File Upload

and keep us up to to date on your progess![/quote]

Thanks for the fast reply! Unfortunately the extension is for situations like this-
Code:
&lt;input type="file" name="file_1" size="20" /&gt;
  &lt;input type="file" name="file_2" size="20" /&gt;
  &lt;input type="file" name="file_3" size="20" /&gt;
Where as i have a different situation
Code:
&lt;input type="file" name="file[]" size="20" /&gt;
&lt;input type="file" name="file[]" size="20" /&gt;
&lt;input type="file" name="file[]" size="20" /&gt;

and its actually doing a mass upload. I want to upload files 1 by 1. Please refer to the original post for more details.

All I need to know how i can pass a single element of the array file[] to $this->upload->do_upload();

Thanks again, I appreciate your interest!




Theme © iAndrew 2016 - Forum software by © MyBB