Wednesday, January 24, 2018

To import data from csv to mysql we need to convert excel file data to csv file and then upload using front end page using php codeigniter framework.
Now we will move to coding part ,Here we need to create three files in codeigniter folders i.e
1) Model file
2) View file
3) Controller file.
Now In the first step we will create View file as Upload_csv.php under View folder.


Now in the second step we will create controller file as User.php under controllers folder.
Here we are uploading the csv file using upload_sampledata function.

Now in the third step we will create Model file as upload_services.php under Models folder.



In the above code i used fgetcsv($fp,1024) to get csv line count and stored in $csv_line variable. Now using for loop read the csv file data and storing in an array and passing to codeigniter default insert function as shown above.
To maintain good website for online money making ,just take good Virtual Private Servers, Built for Open Source Developers , Fully managed, lightning-fast, starting at $15/mo with 1GB RAM! , a developer running a complex application that requires instant scalability, or a designer wanting to give your clients’ sites maximum performance, then VPS hosting is just what you need!
Thank you for reading this article.

Tags: , , , ,
I am Saritha Reddy, a Remote codeigniter,Angularjs Developer. I have 4+ years of strong experience in designing, implementing, Programming and delivering advanced XAMPP ( Apache, MySQL and PHP) Web applications development. I am an Indian national and based Andhra Pradesh,Hyderabad. In addition to providing custom programming and design, I also have extensive experience with Open Source technologies to keep costs down and get websites running with as little fuss and wait as possible.

6 Comments

Alfredo Mattioli August 17, 2015 at 1:59 pm

very helpfull!!! thanks

Ady August 24, 2015 at 8:12 pm

Greetings, I really served this information, thank you. I implement it without problems.

Medbash August 27, 2015 at 11:53 pm

Thank you for your post is really helpful.
however im having a problem running it it gives me these two errors and the file aint empty.

1 Undefined index: userfile
2 fopen(): Filename cannot be empty
please help solve this issue.
Thanx

    joseph reddy August 28, 2015 at 11:46 am

    Hi Medbash, i think your missing form enctype= “multipart/form-data” ,due this you’re not able to read the file name. if your file is not uploaded then you will get above errors.

Akbar Shaikh June 6, 2016 at 7:48 am

I tried with code but not getting output as it shows 404 error…
i am trying to put controller name in url.. but 404

i tried with index method in controller and ive got output with error..
Undefined variable: data

code:
load->view(‘Upload_csv’,$data);
}
public function upload_sampledata()
{
$data[‘result’]=$this->upload_services->upload_sampledata_csv();
$data[‘query’]=$this-> upload_services->get_car_features_info();
// $this->load->view(‘Upload_csv’,$data);
}

public function __construct()
{
//Core controller constructor
parent::__construct();

$this->load->model(‘upload_services’);
$this->load->library(‘form_validation’);

}

}
?>

i know that index method dont know about $data variable how can i resolve this please help..

    admin June 21, 2016 at 4:25 am

    Hi Akbar Shaikh, Please declare $data as global variable it will resolve the issue.Thanks!

Leave a Comment