我收到以下错误:不允许您尝试上载的文件类型。我想上传csv文件。
我正在使用codeigniter文件上传方法do_upload,我还提供了allowed_types作为csv
public function csvRateList(){
$redirectData=['error'=>'','success'=>''];
$type=$this->input->post('type');
date_default_timezone_set('Asia/Kolkata');
$config['upload_path'] ='./csv/';
$config['allowed_types'] = 'csv'; //type of file
$config['max_size'] = '100';
$this->load->library('upload',$config);
$query = $this->db->get_where('csv_rate_list', array('type' => $type));
if($query->num_rows()==0){
$query = $this->db->get_where('rate_list', array('type' => $type));
if($query->num_rows()==0){
if($this->upload->do_upload()){
$fdata=$this->upload->data();
$newName=$fdata['file_name'];
$origName=$fdata['orig_name'];
$data = array(
'type' => $type ,
'new_name' => $newName ,
'orig_name' => $origName,
'timestamp' =>time()
);
$this->db->insert('csv_rate_list', $data);
}else{
$redirectData['error']=$this->upload->display_errors();
redirect(base_url().'add_rate');
}
$redirectData['success']='Successfully inserted!';
$this->session->set_flashdata($redirectData);
redirect(base_url().'add_rate');
}else{
$redirectData['error']='Service type already exists. in old table';
$this->session->set_flashdata($redirectData);
redirect(base_url().'add_rate');
}
}else{
$record=$query->row_array();
$id=$record['id'];
$old_name=$record['new_name'];
if($this->upload->do_upload()){
$fdata=$this->upload->data();
$newName=$fdata['file_name'];
$origName=$fdata['orig_name'];
$data = array(
'type' => $type ,
'new_name' => $newName ,
'orig_name' => $origName,
'timestamp' =>time()
);
$this->db->where('id', $id);
$this->db->update('csv_rate_list', $data);
unlink('./csv/'.$old_name);
$redirectData['success']='Successfully updated!';
$this->session->set_flashdata($redirectData);
redirect(base_url().'add_rate');
}else{
$redirectData['error']=$this->upload->display_errors();
$this->session->set_flashdata($redirectData);
redirect(base_url().'add_rate');
}
}
}发布于 2015-05-07 19:14:42
您必须修改(/system/libraries/Upload.php)中的几行
发自:
$this->file_type = @mime_content_type($file['tmp_name']);
return;要这样做:
$this->file_type = @mime_content_type($file['tmp_name']);
if (strlen($this->file_type) > 0) return; 发布于 2015-05-07 20:03:47
检查config/mimes.php的"csv“值是否正确
在$mimes数组中,找到“csv”并检查以下内容。
'csv‘=>数组(’text/x-逗号分隔值‘,’text/逗号分隔值‘,'application/octet-stream','application/vnd.ms-excel','text/x-csv','text/csv','application/csv','application/excel','application/vnd.msexcel'),
如果不是,则将以下内容添加到其中。
https://stackoverflow.com/questions/30098919
复制相似问题