title: Creating export and import in codeigniter i need an assistant
body: <p>I need an assistant with creating export and import file in codeigniter, I am not advanced in coding, I am still learning. I didn't add export button as I also need an assistant on how to add it</p>
  
  <p>Here is my view</p>
  
  <pre><code>&lt;form method="post" action="&lt;?php echo base_url() ?&gt;csv/importcsv" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="userfile" size="10" style="width:20px;"&gt;
      &lt;input type="submit" name="submit" value="IMPORT" class="btn btn-primary"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my controller</p>
  
  <pre><code>/****MANAGE MEMBERS*****/
  function member($param1 = '', $param2 = '', $param3 = '') {
      if ($this-&gt;session-&gt;userdata('admin_login') != 1)
          redirect(base_url(), 'refresh');
      if ($param1 == 'create') {
          $data['names']                          =   $this-&gt;input-&gt;post('names');
          $data['surname']                        =   $this-&gt;input-&gt;post('surname');
          $data['title']                          =   $this-&gt;input-&gt;post('title');
          $data['initials']                       =   $this-&gt;input-&gt;post('initials');
          $data['id_number']                      =   $this-&gt;input-&gt;post('id_number');
          $data['passport']                       =   $this-&gt;input-&gt;post('passport');
          $data['birthdate']                      =   $this-&gt;input-&gt;post('birthdate');
          $data['gender']                         =   $this-&gt;input-&gt;post('gender');
          $data['email']                          =   $this-&gt;input-&gt;post('email');
          $data['address_1']                      =   $this-&gt;input-&gt;post('address_1');
          $data['address_2']                      =   $this-&gt;input-&gt;post('address_2');
          $data['address_3']                      =   $this-&gt;input-&gt;post('address_3');
          $data['province']                       =   $this-&gt;input-&gt;post('province');
          $data['country']                        =   $this-&gt;input-&gt;post('country');
          $data['postal_code']                    =   $this-&gt;input-&gt;post('postal_code');
          $data['phone']                          =   $this-&gt;input-&gt;post('phone');
          $data['tel']                            =   $this-&gt;input-&gt;post('tel');
          $data['country']                        =   $this-&gt;input-&gt;post('country');
          $data['region']                         =   $this-&gt;input-&gt;post('region');
          $data['branch']                         =   $this-&gt;input-&gt;post('branch');
          $data['creation_timestamp']             =   $this-&gt;input-&gt;post('creation_timestamp');
          $data['expiry_timestamp']               =   $this-&gt;input-&gt;post('expiry_timestamp');
          $data['beneficiary_name']               =   $this-&gt;input-&gt;post('beneficiary_name');
          $data['beneficiary_surname']            =   $this-&gt;input-&gt;post('beneficiary_surname');
          $data['beneficiary_id_number']          =   $this-&gt;input-&gt;post('beneficiary_id_number');
          $data['beneficiary_phone']              =   $this-&gt;input-&gt;post('beneficiary_phone');
          $data['message']                        =   $this-&gt;input-&gt;post('message');
          $data['chat_status']                    =   $this-&gt;input-&gt;post('chat_status');
          $this-&gt;db-&gt;insert('member', $data);
          $member_id = mysql_insert_id();
          move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/member_image/' . $member_id . '.jpg');
          $this-&gt;email_model-&gt;account_opening_email('member', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
          redirect(base_url() . 'index.php?admin/member/', 'refresh');
      }
      if ($param1 == 'do_update') {
          $data['names']                          =   $this-&gt;input-&gt;post('names');
          $data['surname']                        =   $this-&gt;input-&gt;post('surname');
          $data['title']                          =   $this-&gt;input-&gt;post('title');
          $data['initials']                       =   $this-&gt;input-&gt;post('initials');
          $data['id_number']                      =   $this-&gt;input-&gt;post('id_number');
          $data['passport']                       =   $this-&gt;input-&gt;post('passport');
          $data['birthdate']                      =   $this-&gt;input-&gt;post('birthdate');
          $data['gender']                         =   $this-&gt;input-&gt;post('gender');
          $data['email']                          =   $this-&gt;input-&gt;post('email');
          $data['address_1']                      =   $this-&gt;input-&gt;post('address_1');
          $data['address_2']                      =   $this-&gt;input-&gt;post('address_2');
          $data['address_3']                      =   $this-&gt;input-&gt;post('address_3');
          $data['province']                       =   $this-&gt;input-&gt;post('province');
          $data['country']                        =   $this-&gt;input-&gt;post('country');
          $data['postal_code']                    =   $this-&gt;input-&gt;post('postal_code');
          $data['phone']                          =   $this-&gt;input-&gt;post('phone');
          $data['tel']                            =   $this-&gt;input-&gt;post('tel');
          $data['country']                        =   $this-&gt;input-&gt;post('country');
          $data['region']                         =   $this-&gt;input-&gt;post('region');
          $data['branch']                         =   $this-&gt;input-&gt;post('branch');
          $data['creation_timestamp']             =   $this-&gt;input-&gt;post('creation_timestamp');
          $data['expiry_timestamp']               =   $this-&gt;input-&gt;post('expiry_timestamp');
          $data['beneficiary_name']               =   $this-&gt;input-&gt;post('beneficiary_name');
          $data['beneficiary_surname']            =   $this-&gt;input-&gt;post('beneficiary_surname');
          $data['beneficiary_id_number']          =   $this-&gt;input-&gt;post('beneficiary_id_number');
          $data['beneficiary_phone']              =   $this-&gt;input-&gt;post('beneficiary_phone');
          $data['message']                        =   $this-&gt;input-&gt;post('message');
          $data['chat_status']                    =   $this-&gt;input-&gt;post('chat_status');
  
          $this-&gt;db-&gt;where('member_id', $param2);
          $this-&gt;db-&gt;update('member', $data);
          move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/member_image/' . $param2 . '.jpg');
          redirect(base_url() . 'index.php?admin/member/', 'refresh');
      } else if ($param1 == 'personal_profile') {
          $page_data['personal_profile']   = true;
          $page_data['current_member_id'] = $param2;
      } else if ($param1 == 'edit') {
          $page_data['edit_data'] = $this-&gt;db-&gt;get_where('member', array(
                          'member_id' =&gt; $param2
                      ))-&gt;result_array();
      }
      if ($param1 == 'delete') {
          $this-&gt;db-&gt;where('member_id', $param2);
          $this-&gt;db-&gt;delete('member');
          redirect(base_url() . 'index.php?admin/member/', 'refresh');
      }
      $page_data['teachers']   = $this-&gt;db-&gt;get('member')-&gt;result_array();
      $page_data['page_name']  = 'member';
      $page_data['page_title'] = get_phrase('manage_member');
      $this-&gt;load-&gt;view('index', $page_data);
  
      if (!this-&gt;load-&gt;importcsv()); {
          $data['memberbook'] = $this-&gt;csv_model-&gt;get_memberbook();
          $data['error'] = '';    //initialize image upload error array to empty
  
          $config['upload_path'] = './uploads/';
          $config['allowed_types'] = 'csv';
          $config['max_size'] = '1000';
  
          $this-&gt;load-&gt;library('upload', $config);
  
          // If upload failed, display error
          if (!$this-&gt;upload-&gt;do_upload()) {
              $data['error'] = $this-&gt;upload-&gt;display_errors();
  
              $this-&gt;load-&gt;view('index', $data);
          } else {
              $file_data = $this-&gt;upload-&gt;data();
              $file_path =  './uploads/'.$file_data['file_name'];
  
              if ($this-&gt;csvimport-&gt;get_array($file_path)) {
                  $csv_array = $this-&gt;csvimport-&gt;get_array($file_path);
                  foreach ($csv_array as $row) {
                      $insert_data = array(
                                  'names'=&gt;$row['names'],
                                  'surname'=&gt;$row['surname'],
                                  'initials'=&gt;$row['initials'],
                                  'id_number'=&gt;$row['id_number'],
                                  'passport'=&gt;$row['passport'],
                                  'birthdate'=&gt;$row['birthdate'],
                                  'gender'=&gt;$row['gender'],
                                  'phone'=&gt;$row['phone'],
                                  'email'=&gt;$row['email'],
                                  'address_1'=&gt;$row['address_2'],
                                  'address_2'=&gt;$row['address_2'],
                                  'address_3'=&gt;$row['address_3'],
                                  'province'=&gt;$row['province'],
                                  'country'=&gt;$row['country'],
                                  'postal_code'=&gt;$row['postal_code'],
                                  'tel'=&gt;$row['tel'],
                                  'region'=&gt;$row['region'],
                                  'branch'=&gt;$row['branch'],
                                  'creation_timestamp'=&gt;$row['creation_timestamp'],
                                  'expiry_timestamp'=&gt;$row['expiry_timestamp'],
                                  'beneficiary_name'=&gt;$row['beneficiary_name'],
                                  'beneficiary_surname'=&gt;$row['beneficiary_surname'],
                                  'beneficiary_id_number'=&gt;$row['beneficiary_id_number'],
                                  'beneficiary_phone'=&gt;$row['beneficiary_phone'],
                                  'message'=&gt;$row['message'], 
                              );
                  $this-&gt;csv_model-&gt;insert_csv($insert_data);
              }
              $this-&gt;session-&gt;set_flashdata('success', 'Csv Data Imported Succesfully');
              redirect(base_url().'csv');
              //echo "&lt;pre&gt;"; print_r($insert_data);
          } else 
              $data['error'] = "Error occured";
              $this-&gt;load-&gt;view('csvindex', $data);
          }                       
      }       
  }
  </code></pre>