Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

php - Uploading in Codeigniter - The filetype you are attempting to upload is not allowed

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

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

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

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'),
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

1) modify Line number 1044

from:

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

to this:

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

2) modify line number 1058

from:

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

to this:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...