这是我的代码
function importcsv()
{
$data['addressbook'] = $this->csv_model->get_addressbook();
$data['error'] = ''; //initialize image upload error array to empty
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '1000';
$this->load->library('upload', $config);
// If upload failed, display error
if (!$this->upload->do_upload()) {
$data['error'] = $this->upload->display_errors();
$this->load->view('csvindex', $data);
}
else {
$file_data = $this->upload->data();
$file_path = './uploads/' . $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(
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'birthday' => $row['birthday'],
'email' => $row['email'],
);
$this->csv_model->insert_csv($insert_data);
}
$this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
redirect(base_url() . 'csv');
// echo "<pre>"; print_r($insert_data);
}
else $data['error'] = "Error occured";
$this->load->view('csvindex', $data);
}
}
在localhost上传工作正常但在服务器上我得到&#34;您尝试上传的文件类型不允许&#34;。
Mysql所有权限也是活动的,也是文件权限755.我也尝试将权限更改为777,但它没有帮助。
答案 0 :(得分:0)
该消息基本上表示不允许服务器接收此类文件。您可能需要修改服务器配置以启用CSV文件的上传。 (查看localhost的配置,因为它正在运行)
答案 1 :(得分:0)
只需编辑application / config / mimes.php中的mimes.php文件,并用以下内容替换csv的行:
'csv' => array('application/vnd.ms-excel', 'text/anytext', 'text/plain', 'text/x-comma-separated-values'
OR config.php将此更改为
'allowed_types' => 'text/plain|text|csv|csv',
答案 2 :(得分:0)
在application / config / mimes.php中的mimes.php文件中替换'csv'解决了
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),