0

尝试上传 .ini 文件时出现以下错误

“您尝试上传的文件类型不被允许。”

下面是上传文件的功能

  private function _upload_config_file() {

    $config['upload_path'] = APPPATH . 'config/ini/';
    $config['allowed_types'] = 'ini';
    $config['max_size'] = '2000000';
    $this->load->library('upload', $config);
    if ($this->upload->do_upload()) {
        $this->upload_status = 'File uploaded succesfully !';
        return true;
    } else {
        $this->upload_status = $this->upload->display_errors();
        return false;
    }
}

在视图中

$upload_file_attr = array(
                    'name' => 'userfile',
                    'id' => 'userfile',
                    'disabled' => 'disabled'
);
   echo form_open_multipart('sys_setting', $form_sys_setting_multi);
   echo form_label('Configure Manually' . form_checkbox($upload_checkbox, '', FALSE, $js_checkbox));
   echo form_button($download_button);
   echo form_upload($upload_file_attr);
   echo form_reset($upload_reset);
   echo form_submit($upload_submit);
   echo form_close();

php.ini 中是否需要对上传 .ini 文件进行任何更改?

还是codeigniter的上传库不允许上传.ini文件?

需要建议来解决这个问题。

4

2 回答 2

0

你忘了把 field_name

尝试添加这个:

 if ($this->upload->do_upload('userfile')) { //parameter should the your input file name attribute
        $this->upload_status = 'File uploaded succesfully !';
        return true;
    } else {
        $this->upload_status = $this->upload->display_errors();
        return false;
    }
于 2013-11-13T06:51:18.293 回答
0

我解决了这个问题。在 config/mimes.php 修改 $mimes 数组

     $mimes = array('ini' => 'application/octet-stream')

如果有人知道如何在不修改核心文件的情况下解决此问题,*请发表评论。*

于 2013-11-15T13:07:32.997 回答