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'))