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

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.

Leave a Comment