• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI3: Multiple File Upload

#1
Hi Guys,

Basing from http://www.codeigniter.com/userguide3/li...ading.html I'm trying to implement method ('process_upload'), that would upload multiple files. the idea is basically from the tutorial, only i added some loop just in case of multiple input.
PHP Code:
public function process_upload$input_field_name$config = array() ) {
 
 for ($key 0$key count($_FILES[$input_field_name]['name']); $key++) {
 
   $_FILES[$input_field_name]['name'    $_FILES[$input_field_name]['name'][$key];
 
   $_FILES[$input_field_name]['type'    $_FILES[$input_field_name]['type'][$key];
 
   $_FILES[$input_field_name]['tmp_name'] = $_FILES[$input_field_name]['tmp_name'][$key];
 
   $_FILES[$input_field_name]['error'   $_FILES[$input_field_name]['error'][$key];
 
   $_FILES[$input_field_name]['size'    $_FILES[$input_field_name]['size'][$key];

 
   $this->load->library('upload'$config);

 
   if ( !$this->upload->do_upload($input_field_name) ) {
 
     return array('upload_error' => $this->upload->display_errors());
 
   } else {
 
     return array('upload_data' => $this->upload->data());
 
      
  
 


Then call the method ('process_upload') in other method ('set_upload') like:
PHP Code:
public function set_upload() {
 
 // Config your upload settings
 
 $config['upload_path'     './public/images/';
 
 $config['allowed_types'   'gif|jpg|png';
 
 $config['max_size'        '100';
 
 $config['max_width'       '1024';
 
 $config['max_height'      '768';

 
 $field 'myfile'// Input File field
 
 $data $this->process_upload($field$config);

Now, if i try to upload 3 files, only 1 file is uploaded  to its upload path directory. Cany anyone please help, how can i resolved this issue.

Thanks, in advanced.
Reply

#2
You must have multiple in your upload input like this...
<input type="file" name="userfile" size="20" multiple>
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply

#3
If you have the time, please do look at my latest tutorial about uploading multiple files: http://avenir.ro/codeigniter-tutorials/u...deigniter/
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.