【问题标题】:uploading .ini files in CI在 CI 中上传 .ini 文件
【发布时间】:2013-11-13 06:27:38
【问题描述】:

尝试上传 .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();

上传.ini文件需要在php.ini中做些修改吗?

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

需要解决此问题的建议。

【问题讨论】:

  • 你能展示你的 FORM 元素吗?
  • @DrixsonOseña 请检查更新后的问题。
  • 确保您可以上传 .ini 文件。一些主机禁用某种文件进行上传(在我的情况下,我的主机禁用了上传 .ini 文件,但 CI 向我显示了同样的错误)
  • @Red ,谢谢你的建议,你也可以看看我应该在哪里查看是否不允许上传某种文件。我检查了 php.ini 文件,有'没有任何允许上传类型的选项
  • @Christopher 我不确定你的情况。你试过没有 CI 吗?

标签: php codeigniter file-upload


【解决方案1】:

你忘了输入字段名

尝试添加这个:

 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;
    }

【讨论】:

  • 默认其用户文件在上传库公共函数do_upload($field = 'userfile')
  • 你可以通过回显$_FILES['files']['type']来检查你上传的文件是什么
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-14
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 2011-01-17
    相关资源
    最近更新 更多