0

I want to upload files with CodeIgniter through generated numbered upload fields :

<input type='file' name='field[0]' />
<input type='file' name='field[1]' />

These upload fields are among another inputs fields :

<input type='file' name='field[0]' />
<input type='TEXT' name='field[1]' />
<input type='file' name='field[2]' />

I just want to upload the files when the user click on the Submit button and keep this specific inputs structure

I've tried this but it doesn't work :

     for($i=0; $i<count($_FILES); $i++)
     {

       $config['upload_path']   = './uploads/';
       $config['allowed_types'] = 'jpg|jpeg|gif|png';
       $config['overwrite']     = FALSE;

      $this->upload->initialize($config);
$this->upload->do_upload('field['.$i.']');


     }

Any help would be very appreciated! Thanks!

3

1 Answer 1

1

That did the trick :

foreach ($_FILES['field']['name'] as $i => $name) { 

     if ($_FILES['field']['error'][$i] == 4) { 
         continue;  
     } 

     if ($_FILES['field']['error'][$i] == 0) { 

          if ($_FILES['field']['size'][$i] > 99439443) { 
             $message[] = "$name exceeded file limit."; 
             continue;   
          } 

         /* 
          * Check File Extension 
          * Move  File            
          */   

            echo $name;
            echo '<br />';

            $uploads_dir = $config['upload_path'] = './uploads/thumbs/'.$this->session->userdata('raw_name');

            $tmp_name = $_FILES["field"]["tmp_name"][$i];
            $name = $_FILES["field"]["name"][$i];
            move_uploaded_file($tmp_name, "$uploads_dir/$name");        

     } 
}

Unfortunately, not in CodeIgniter way :( It doesn't work and I don't know why, but this works well

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.