加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – CodeIgniter“不允许您尝试上传的文件类型.”

发布时间:2020-12-13 22:40:04 所属栏目:PHP教程 来源:网络整理
导读:我经常搜索并发现很多关于这个问题的问题,遗憾的是没有一个答案对我有帮助. 我正在尝试上传png图像,我收到以下错误: The filetype you are attempting to upload is not allowed. 我正在遵循此CI指南来构建我的代码:http://codeigniter.com/user_guide/lib
我经常搜索并发现很多关于这个问题的问题,遗憾的是没有一个答案对我有帮助.

我正在尝试上传png图像,我收到以下错误:

The filetype you are attempting to upload is not allowed.

我正在遵循此CI指南来构建我的代码:http://codeigniter.com/user_guide/libraries/file_uploading.html

这是我得到的:

查看文件:

[..]
   <?= form_open_multipart() ?>
   <input type="file" name="userfile" size="20" />
   <br /><br />
   <input type="submit" value="upload" />
   <?= form_close() ?>
[..]

我的控制器:

$config['upload_path']   = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '100';
    $config['max_width']     = '1024';
    $config['max_height']    = '768';


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

        $xx = array('upload_data' => $this->upload->data());
        $mimetype= $xx['upload_data']['file_type'];

        var_dump('Mime: ' . $mimetype);
        var_dump($_FILES);

        if ( !$this->upload->do_upload())
        {
            Notice::add($this->upload->display_errors(),'error');
        }
        else
        {
            $data['upload_data'] = $this->upload->data();
        }

正如你所看到的,我正在尝试var_dump mime类型,结果为空.

当我做var_dump($_ FILES)时,看起来一切都很好:

array(1) { ["userfile"]=> array(5) { ["name"]=> string(14) "imageofm.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(18) "/var/tmp/php5cDAZJ" ["error"]=> int(0) ["size"]=> int(358) } }

另外,我得到’png’=>数组(‘image / png’,’image / x-png’),line,在我的config / mimes.php中.

但是,它确实发生在所有图像上(还没有尝试过其他扩展).

我很感激每一次尝试.

只需编辑application / config / mimes.php中的mimes.php文件,并用以下内容替换csv的行:
'csv' => array('application/vnd.ms-excel','text/anytext','text/plain','text/x-comma-separated-values','text/comma-separated-values','application/octet-stream','application/vnd.ms-excel','application/x-csv','text/x-csv','text/csv','application/csv','application/excel','application/vnd.msexcel')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读