我在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