I am trying to insert records using csv. I want to upload csv to my Application and want to import it in database. Now I have a users table so i want to create users by importing user's csv file. I Know a little about file uploads but nil about importing it into database please help .
See I have done the file upload using : Controller:
public function upload_csv()
{
$this->load->helper('form');
$this->load->helper('url');
//Set the message for the first time
$data = array('msg' => "Upload File");
$data['upload_data'] = '';
//load the view/upload.php with $data
$this->load->view('admin/user/upload', $data);
}
The Another Controller Upload_file
public function upload_it() {
//load the helper
$this->load->helper('form');
//Configure
//set the path where the files uploaded will be copied. NOTE if using linux, set the folder to permission 777
$config['upload_path'] = 'application/views/uploads/';
// set the filter image types
$config['allowed_types'] = 'gif|csv';
//load the upload library
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
$data['upload_data'] = '';
//if not successful, set the error message
if (!$this->upload->do_upload('userfile')) {
$data = array('msg' => $this->upload->display_errors());
} else { //else, set the success message
$data = array('msg' => "Upload success!");
$data['upload_data'] = $this->upload->data();
}
//load the view/upload.php
$this->load->view('admin/user/upload', $data);
}
And The view:
<code>
<?php if($upload_data != ''):?>
<?php var_dump($upload_data);?>
</code>
<img scr="<?php echo $upload_data['full_path'];?>">
<?php endif;?>
<?php echo form_open_multipart('admin/upload_file/upload_it');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
Now How do i import a uploaded file into my database ??