在 Codeigniter 中上传 - 您尝试上传的文件类型是不允许的 [英] Uploading in Codeigniter - The filetype you are attempting to upload is not allowed

查看:33
本文介绍了在 Codeigniter 中上传 - 您尝试上传的文件类型是不允许的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:当我尝试上传任何文件时,不允许您尝试上传的文件类型.

I am getting the error: The filetype you are attempting to upload is not allowed when I try to uplaod any file.

if(!empty($_FILES['proof_of_purchase']['name'])) {
    $config['upload_path'] = './uploads/invoices/';
    $config['allowed_types'] = 'gif|jpg|jpeg|png|pdf|bmp';
    $config['max_size'] = '3000';
    $this->load->library('upload', $config);
  
      // if there was an error, return and display it
    if (!$this->upload->do_upload('proof_of_purchase'))
    {
        $data['error'] = $this->upload->display_errors();
        $data['include'] = 'pages/classic-register';
    } else {
        $data['upload_data'] = $this->upload->data();
        $filename = $data['upload_data']['file_name'];
    }
}

我尝试了许多不同的文件——主要是 gif 和;jpeg 并每次都得到相同的错误.

I have tried many different files- mostly gif & jpeg and get the same error each time.

var_dump($_FILES);给我:

var_dump($_FILES); gives me:

array(1) { ["proof_of_purchase"]=> array(5) { ["name"]=> string(28) "2010-12-04_00019.jpg" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(19) "D:	empphp2BAE.tmp" ["error"]=> int(0) ["size"]=> int(58054) } } 

我已经检查了 mime 配置,它包含正确的内容.示例:

I have checked the mime config and it contains the right stuff. Example:

'jpeg'  =>  array('image/jpeg', 'image/pjpeg'),
'jpg'   =>  array('image/jpeg', 'image/pjpeg'),
'jpe'   =>  array('image/jpeg', 'image/pjpeg'),

推荐答案

如果您使用的是 Codeigniter 2.1.0 版,则上传库中存在错误.有关详细信息,请参阅 http://codeigniter.com/forums/viewthread/204725/.

If you're using Codeigniter version 2.1.0 there is a bug in the Upload library. See http://codeigniter.com/forums/viewthread/204725/ for more details.

基本上我所做的是修改文件上传类中的几行代码(位置:./system/libraries/Upload.php)

Basically what I did was modify a few lines of code in the File Upload Class (Location: ./system/libraries/Upload.php)

1) 修改行号 1044

1) modify Line number 1044

来自:

$this->file_type = @mime_content_type($file['tmp_name']);
return;

为此:

$this->file_type = @mime_content_type($file['tmp_name']);
if (strlen($this->file_type) > 0) return; 

2) 修改行号 1058

2) modify line number 1058

来自:

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);

为此:

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_name']), $output, $return_code); 

正如您可能看到的,第 1058 行尝试使用不存在的数组值.

As you can probably see, line 1058 tries to use an array value that does not exist.

这篇关于在 Codeigniter 中上传 - 您尝试上传的文件类型是不允许的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆