CSV上传无法正常运行

时间:2015-07-29 07:30:48

标签: php mysql codeigniter

在此,我想上传csv文件。验证不正确,但没有验证其工作。

这是我的控制者:

public function uploadstatetype()
{
         $config['upload_path'] = APPPATH.'/assets/upload/';
         $config['allowed_types'] = 'csv';
        $config['max_size']  = '5000';
        with = ' ';
   $replace = '"';

     $this->load->library('upload', $config);
    $this->load->database();

if ( ! $this->upload->do_upload('file_name'))
{
    $error = array('error' => $this->upload->display_errors());
    $this->managestate($error);
}
else
{

//将文件信息插入数据库

    $data = array('upload_data' => $this->upload->data());
    $userfile = $data['upload_data']['file_name'];
    $this->load->library('csvreader');
    $upload_data = $this->upload->data(); 
    $this->load->library('csvreader');
    $file =  $upload_data['full_path'];
    $file_name =  $upload_data['userfile']; 

   $data = $this->csvreader->parse_file($file);

   foreach($data as $row)
   {

       if(($row['state_id']=='')||($row['state_name']==''))     
   {
     $this->session->set_flashdata('msg_excel','Please check the details in the file, some details are empty.');
    redirect(base_url().'admin/businesslocation/managestate');
 } 
 else
 {
     $results_array = array(
                       'state_id' => $row['state_id'],
                       'state_name' => $row['state_name'] 
                       );         
    $this->load->model('admin/businesslocation_model');
    $this->businesslocation_model->stateupload($results_array); 
    $success_message='Successfully Upload!';
    $this->session->set_flashdata('success_message',$success_message); 
    redirect(base_url().'admin/businesslocation/managestate');   

 }                        
}

} 
}

这是我的模特:

       function stateupload($results_array)
{

       $this->db->insert('cr_state', $results_array);



}

例如state_id = 1和state_name =“kerala”。然后插入工作,当未检查条件时。但是,如果条件得到,它就不起作用了。

1 个答案:

答案 0 :(得分:0)

像这样改变你的状况并尝试

   if(empty($row['state_id'])||(empty($row['state_name']))){