微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我经常搜索并发现很多关于这个问题的问题,遗憾的是没有一个答案对我有帮助.

我正在尝试上传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')

原文地址:https://www.jb51.cc/php/133232.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐