我有这样的代码
function upload() {
$this->db->empty_table('area_proses');
$data['error'] = ''; //initialize image upload error array to empty
$config['upload_path'] = './coba_upload/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '20';
$this->load->library('upload', $config);
$data['level'] = $this->session->userdata('level_id');
$data['email'] = $this->session->userdata('email');
$data['include'] = $this->load->view('/read/include','',TRUE);
$data['content'] = $this->load->view('/read/upload',$data,TRUE);
$this->load->view("admin/main",$data);
// If upload failed, display error
if (!$this->upload->do_upload()) {
$data['error'] = $this->upload->display_errors();
//$this->load->view('/read/upload', $data);
} else {
$file_data = $this->upload->data();
$file_path = './coba_upload/'.$file_data['file_name'];
if ($this->csvimport->get_array($file_path)) {
$csv_array = $this->csvimport->get_array($file_path);
foreach ($csv_array as $row) {
$insert_data = array(
'id'=>$row['id'],
'area_proses'=>$row['area_proses'],
'sg1'=>$row['sg1'],
'sg2'=>$row['sg2'],
'sg3'=>$row['sg3'],
'avg'=>$row['avg'],
'fuzzy'=>$row['fuzzy'],
);
$this->model->insert_csv($insert_data);
}
$this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
redirect(base_url().'area_proses');
//echo "<pre>"; print_r($insert_data);
} else
$data['include'] = $this->load->view('/read/include','',TRUE);
$data['content'] = $this->load->view('/read/upload',$data,TRUE);
$this->load->view("admin/main",$data);
}
}
问题是我可以上传一个csv文件插入localhost(xampp)中的数据库但是当我托管它时,代码不起作用,只删除数据而不是读取csv以插入数据库
你有解决方案吗?答案 0 :(得分:0)
首先,您应该检查LOAD DATA INFILE以将csv导入数据库。 如果您的数据量巨大,那么它比循环更好。