我在CodeIgniter中设置了一个上传表单。我已将allowed_types参数设置为:
$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']);
}
}
答案 0 :(得分:0)
请试试这个
$this->load->library('upload', $config);
$this->upload->initialize($config);
答案 1 :(得分:0)
你试过这个吗?
if (!$this->upload->do_upload('put the name of the input field here'))