2014-12-05 113 views
0

我在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']); 

    } 

} 
+0

你为什么要评论这一行// $ config ['allowed_types'] ='xls | xlsx'; – 2014-12-05 11:33:56

+0

这是一个错误,未注释现在,但仍得到相同的错误 – MrD 2014-12-05 11:35:03

+0

应用/ vnd.openxmlformats-officedocument.spreadsheetml.sheet 试试这个作为MIME类型进行XLSX – 2014-12-05 11:39:28

回答

0

请试试这个

$this->load->library('upload', $config); $this->upload->initialize($config);

+0

仍然无效:/ – MrD 2014-12-05 11:43:45

+0

先尝试** xls **并尝试** xlxs **汝获得错误? – 2014-12-05 11:44:51

+0

XLS正在工作:) – MrD 2014-12-05 11:45:43

0

你试过吗?

if (!$this->upload->do_upload('put the name of the input field here'))