Welcome Guest, Not a member yet? Register   Sign In
Uploading multiple files userfile[] array??
#1

[eluser]Wonder Woman[/eluser]
Hi,

I am trying to upload multiple images and I have a jquery plugin set up so I can browse for multiple files and select them.

The only problem I am having is accessing the file array in my controller, anyone know how I can do this? Thanks.

view:
Code:
<input type="file" name="userfile[]" id="userfile" class="multi" />
#2

[eluser]Ivoo[/eluser]
You should have a global array $_FILES that holds the data for the uploaded files.

See http://php.net/manual/en/reserved.variables.files.php
#3

[eluser]ludo31[/eluser]
please try to adapt your code with that :

view
http://pastie.org/3679320

controller
http://pastie.org/3679335

view success
http://pastie.org/3679342

may be you can use but you must do a foreach after

Code:
/* on recupere via $_FILES */
                
                foreach($_FILES as $key =>$value)
                {
                    
                  
                    /* on teste si le nom est vide */
                    
                    if (isset($value['name']))
                    {
#4

[eluser]ci_fan[/eluser]
Hi ludo31.

Thanks for your great example, but I have 1 problem

My view:

Code:
<span>Upload House</span>
&lt;input type="file" name="houseImage"  id="houseImage"/&gt;
<br />
&lt;input type="file" name="houseImage2" id="houseImage2"/&gt;

<span>Upload Garden</span>
&lt;input type="file" name="garden"  id="garden"/&gt;
<br />
&lt;input type="file" name="garden2" id="garden2"/&gt;
<br />
&lt;input type="file" name="garden3" id="garden3"/&gt;

I want to separate the upload for House, Garden <-- it will store in different table in database
I don't know how to get each of them
Please help
Best regards
#5

[eluser]ci_fan[/eluser]
In my controler:

Code:
$config['upload_path'] = './assets/upload/';
   $config['allowed_types'] = 'gif|jpg|jpeg|png';
   $config['max_size'] = '2048';
   $config['encrypt_name'] =TRUE;
   $this->load->library('upload', $config);
   foreach($_FILES as $file => $value)
   {
    if (! $this->upload->do_upload($file))
    {
      $uploaded_info['error'][]  =  array_merge($this->upload->data(),
     array('error_msg' => $this->upload->display_errors()));
    
    }
    else
    {
      $uploaded_info['success'][] =  array_merge($this->upload->data(),
     array('error_msg' => $this->upload->display_errors()));
    }
    var_dump($uploaded_info);
   }

It works, upload all the files to server, but I won't know which one belong to House, Garden Sad
Thanks for your time
Best regards,
#6

[eluser]ludo31[/eluser]
if you want to know the name of image
change

Code:
$config['encrypt_name'] =TRUE;
to

Code:
$config['encrypt_name'] =FALSE;




Theme © iAndrew 2016 - Forum software by © MyBB