【问题标题】:CodeIgniter's file upload library ignores allowed_types?CodeIgniter 文件上传库忽略 allowed_types?
【发布时间】:2013-03-13 14:40:03
【问题描述】:

我尝试上传证书文件失败:

$config["allowed_types"] = "cer";
$this->load->library("upload", $config);
$this->upload->do_upload("fieldname");

即使我上传 .cer 文件,我总是会收到以下错误:

The filetype you are attempting to upload is not allowed

这是骗人的,我上传了一个允许类型的文件! 为什么这个类会忽略它的documented 设置 allowed_types?

【问题讨论】:

    标签: php codeigniter file-upload file-extension


    【解决方案1】:

    您需要在mimes.php 配置文件中添加mime 类型。应该是这样的:

    'cer' => array('application/x-x509-ca-cert', 'application/octet-stream'),
    

    mime 的位置:application/config/mime.php

    【讨论】:

      【解决方案2】:

      当 csv 由 excel 生成时,我在尝试上传 csv 时遇到了类似的问题 - 最后我不得不使用扩展的 mime 类型列表来允许上传文件。我快速搜索了 .cer mime-types 并找到了两个候选者,请尝试使用:

       $config['allowed_types']  = 'cer|application/x-x509-ca-cert|application/pkix-cert';
      

      【讨论】:

        猜你喜欢
        • 2014-06-25
        • 1970-01-01
        • 1970-01-01
        • 2022-01-05
        • 1970-01-01
        • 2011-11-08
        • 1970-01-01
        • 2015-07-24
        • 1970-01-01
        相关资源
        最近更新 更多