我在CodeIgniter中设置了一个上传表单。我设置了allowed_types参数设置为:CodeIngniter文件上传不允许
$config['allowed_types'] = 'xls|xlsx';
,并添加下面一行到config/mimes.php:
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
然而,尽管该文件我想上传作为一个XLSX文件CI仍然告诉我文件类型不被允许。有什么想法吗?
public function do_upload() {
// Change this if you change the upload directory
$upload_path = "/webusers/ad6vcf/public_html/funding_manager/application/uploads";
$config['upload_path'] = $upload_path;
//At some point will add support for csv
$config['allowed_types'] = 'xls|xlsx';
//Max 5000kb please
$config['max_size'] = '5000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->upload($error);
} else {
$upload_data = $this->upload->data();
bulk_insert($upload_path . $upload_data['file_name']);
}
}
你为什么要评论这一行// $ config ['allowed_types'] ='xls | xlsx'; – 2014-12-05 11:33:56
这是一个错误,未注释现在,但仍得到相同的错误 – MrD 2014-12-05 11:35:03
应用/ vnd.openxmlformats-officedocument.spreadsheetml.sheet 试试这个作为MIME类型进行XLSX – 2014-12-05 11:39:28