Welcome Guest, Not a member yet? Register   Sign In
how to upload multiple file in a single form in codeigniter
#4

[eluser]Bigil Michael[/eluser]
use for loop to upload more than one image at a time

controller

Code:
function demo(){
  
  if($this->input->post('Submit')){
     for($i=1;$i<=6;$i++)
   {
      if($_FILES['photo_'.$i]['name']!=''){
       //upload thumbnail      $c
     $config['upload_path'] = 'Your folder path';
     $config['allowed_types'] = 'gif|jpg|jpeg|png';
     $config['file_name'] = '0'.$i;
     $config['max_size'] = '150';    
     $this->load->library('upload');
     $this->upload->initialize($config);
     if ( ! $this->upload->do_upload('photo_'.$i))
     {
      $data['alert'] = $this->upload->display_errors();
      
     }
     else
     {
      $upload_data = $this->upload->data();
      $filename = $upload_data['file_name'];
      $width = $upload_data['image_width'];
      $height = $upload_data['image_height'];
      $config1 = array();
      $this->load->library('image_lib');
      $config1['source_image'] = 'your folder/'.$filename;
      if($width>762){
       //resize image
       $sizes = array('width' => $width, 'height' => $height, 'new_width' => 762, 'new_height' => 325);
       $newsize = array();
       $newsize = $this->image_lib->size_calculator($sizes);
       $config1['maintain_ratio'] = FALSE;
       $config1['width'] = $newsize['new_width'];
       $config1['height'] = $newsize['new_height'];
       $this->image_lib->initialize($config1);
       $this->image_lib->resize();
       $this->image_lib->clear();
      }
                                                // creating thumb
      $config1['maintain_ratio'] = FALSE;
      $config1['width'] = 762;
      $config1['height'] = 325;
      $config1['create_thumb'] = TRUE;
      $config1['thumb_marker'] = 'thumb_';
      $this->image_lib->initialize($config1);
      $this->image_lib->resize();      
      $this->Your model->save_image('photo_'.$i,$filename);
      $data['alert'] = 'image uploaded';
     }
      }
    }
    $data['image'] = $this->Yoourmodel->get_homepage(); // select photos
    $this->load->view('your view', $data);
      
  }else{
    $this->load->view('your view', $data);
  }
}

model

Code:
function save_image($field,$filename=''){
  
    if($filename!=''){
   $data[$field] = $filename;
  }
  $this->db->where('id',1);// item  id
  $this->db->update('home',$data);
}


Messages In This Thread
how to upload multiple file in a single form in codeigniter - by El Forum - 04-10-2013, 03:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB