Hello,
I am working on Wamp server. Almost code is working are fine but work in import excle file code but error is 404 page not found.I am using only view and controllers, i am new in codeigniter.
Please Help me.
csvToMySQL.php
<a href="javascript:void(0);" onclick="$('#importFrm').slideToggle();">Import Members</a>
<div class="panel-body">
<form action="csvToMySQL/upload_file" method="post" enctype="multipart/form-data" id="importFrm">
<input type="file" name="file" />
<input type="submit" class="btn btn-primary" name="importSubmit" value="IMPORT">
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Created</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
//get rows query
$query = $this->db->query("SELECT * FROM member ORDER BY name")->result();
if(count($query)>0){
foreach($query as $row){ ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->created; ?></td>
<td><?php echo ($row->status == '1')?'Active':'Inactive'; ?></td>
</tr>
<?php } }else{ ?>
<tr><td colspan="5">No member(s) found.....</td></tr>
<?php } ?>
</tbody>
</table>
Controllers Part
Welcome.php
<?php
// defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('csvToMySQL');
echo "HHHHHHHH";
}
public function upload_file(){
$csvMimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'],$csvMimes)){
if(is_uploaded_file($_FILES['file']['tmp_name'])){
//open uploaded csv file with read only mode
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
// skip first line
// if your csv file have no heading, just comment the next line
fgetcsv($csvFile);
//parse data from csv file line by line
while(($line = fgetcsv($csvFile)) !== FALSE){
//check whether member already exists in database with same email
$result = $this->db->get_where("member", array("email"=>$line[1]))->result();
if(count($result) > 0){
//update member data
$this->db->update("member", array("name"=>$line[0], "phone"=>$line[2], "created"=>$line[3], "status"=>$line[4]), array("email"=>$line[1]));
}else{
//insert member data into database
$this->db->insert("member", array("name"=>$line[0], "email"=>$line[1], "phone"=>$line[2], "created"=>$line[3], "status"=>$line[4]));
}
}
//close opened csv file
fclose($csvFile);
$qstring["status"] = 'Success';
}else{
$qstring["status"] = 'Error';
}
}else{
$qstring["status"] = 'Invalid file';
}
$this->load->view('csvToMySQL',$qstring);
}
}