Welcome Guest, Not a member yet? Register   Sign In
CI mime types cause error with file upload
#1

[eluser]charlie spider[/eluser]
[ i accidently posted this in Bug Reports at first, so apoligies to anybody that sees this twice ]

i copied the mime types array from the APP/config/mimes.php file,
then stripped out some of the file types i didn’t want, ( a mime is a terrible thing to waste )
then used that to create my list of allowed file types for file uploading
Code:
$mimes = array(    
        'csv'    =>    array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
        'psd'    =>    'application/x-photoshop',
        'pdf'    =>    array('application/pdf', 'application/x-download'),
        'ai'    =>    'application/postscript',
        'eps'    =>    'application/postscript',
        'ps'    =>    'application/postscript',
        'xls'    =>    array('application/excel', 'application/vnd.ms-excel'),
        'ppt'    =>    array('application/powerpoint', 'application/vnd.ms-powerpoint'),
        'gtar'    =>    'application/x-gtar',
        'gz'    =>    'application/x-gzip',
        'swf'    =>    'application/x-shockwave-flash',
        'tar'    =>    'application/x-tar',
        'tgz'    =>    'application/x-tar',
        'xhtml'    =>    'application/xhtml+xml',
        'xht'    =>    'application/xhtml+xml',
        'zip'    =>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
        'mid'    =>    'audio/midi',
        'midi'    =>    'audio/midi',
        'mpga'    =>    'audio/mpeg',
        'mp2'    =>    'audio/mpeg',
        'mp3'    =>    array('audio/mpeg', 'audio/mpg'),
        'aif'    =>    'audio/x-aiff',
        'aiff'    =>    'audio/x-aiff',
        'aifc'    =>    'audio/x-aiff',
        'ram'    =>    'audio/x-pn-realaudio',
        'rm'    =>    'audio/x-pn-realaudio',
        'rpm'    =>    'audio/x-pn-realaudio-plugin',
        'ra'    =>    'audio/x-realaudio',
        'rv'    =>    'video/vnd.rn-realvideo',
        'wav'    =>    'audio/x-wav',
        'bmp'    =>    'image/bmp',
        'gif'    =>    'image/gif',
        'jpeg'    =>    array('image/jpeg', 'image/pjpeg'),
        'jpg'    =>    array('image/jpeg', 'image/pjpeg'),
        'jpe'    =>    array('image/jpeg', 'image/pjpeg'),
        'png'    =>    array('image/png',  'image/x-png'),
        'tiff'    =>    'image/tiff',
        'tif'    =>    'image/tiff',
        'css'    =>    'text/css',
        'html'    =>    'text/html',
        'htm'    =>    'text/html',
        'shtml'    =>    'text/html',
        'txt'    =>    'text/plain',
        'text'    =>    'text/plain',
        'log'    =>    array('text/plain', 'text/x-log'),
        'rtx'    =>    'text/richtext',
        'rtf'    =>    'text/rtf',
        'xml'    =>    'text/xml',
        'xsl'    =>    'text/xml',
        'mpeg'    =>    'video/mpeg',
        'mpg'    =>    'video/mpeg',
        'mpe'    =>    'video/mpeg',
        'qt'    =>    'video/quicktime',
        'mov'    =>    'video/quicktime',
        'avi'    =>    'video/x-msvideo',
        'movie'    =>    'video/x-sgi-movie',
        'doc'    =>    'application/msword',
        'docx'    =>    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'xlsx'    =>    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'word'    =>    array('application/msword', 'application/octet-stream'),
        'xl'    =>    'application/excel',
        'eml'    =>    'message/rfc822'
);

$config['allowed_types'] = 'cpt'; // enter first element manually

foreach ( $mimes as $mime => $type )
{
    $config['allowed_types'] .= '|' . $mime; // add additional elements preceeded with a pipe
}


echoing the allowed_types produces this :

cpt|csv|psd|pdf|ai|eps|ps|xls|ppt|gtar|gz|swf|tar|tgz|xhtml|xht|zip|mid|midi|mpga|mp2|mp3|aif|aiff|aifc|ram|rm|rpm|ra|rv|wav|bmp|gif|jpeg|jpg|jpe|png|tiff|tif|css|html|htm|shtml|txt|text|log|rtx|rtf|xml|xsl|mpeg|mpg|mpe|qt|mov|avi|movie|doc|docx|xlsx|word|xl|eml

which looks ok to my (naive?) eye.


then, if i try to upload any kind of file (i’m using a txt file for testing purposes) i get:

The filetype you are attempting to upload is not allowed.

that’s in FF3, IE7, and Chrome


if i reduce the allowed types to simply:
Code:
$config['allowed_types'] = 'txt';
then it works fine, so i know the problem isn’t elsewhere.



Does anybody have any golden nuggets of wisdom and/or experience they can share that might help to solve this problem ?
Or has anybody else experienced one of the above mime types throwing the whole machine out of whack ?

Thanks in advance for any and all advice.
#2

[eluser]charlie spider[/eluser]
just discovered that if i comment out:

Code:
'gif'    =>    'image/gif',
'jpeg'    =>    array('image/jpeg', 'image/pjpeg'),
'jpg'    =>    array('image/jpeg', 'image/pjpeg'),
'jpe'    =>    array('image/jpeg', 'image/pjpeg'),
'png'    =>    array('image/png', 'image/x-png'),

from the $mimes array then it works fine and allows me to upload a txt file !?!?!?

any ideas ?
#3

[eluser]Unknown[/eluser]
Hi,

I just checked the upload of pdf with your mime config and it seems to work on my side...

I had the same problem to upload pdf file using the file upload class demonstrated in the user guide of code igniter.

At first it didn't want to upload my pdf with the following settings:

--> $config['allowed_types'] = 'png|jpg|doc|csv|psd|gif|pdf';

Then if you have a close look at the function "do_upload" in the upload.php, you'll find when your pdf file is rejected for "invalid type" issue.

It is actually in the function "is_allowed_filetype" in upload.php. The algorithm is kind of reverse inside if can say that.

So accordingly to the algo of "is_allowed_filetype" function, you just need to change the position of your pdf in the config array, you'll end up with something like this:

--> $config['allowed_types'] = 'pdf|png|jpg|doc|csv|psd|gif';

And this worked actually alright for me regardless the mime type config.

It's true it's a bit messy i agree, i just hope that code igniter either clears this up or comes up with a fix...

Hope it might helps ;-)
#4

[eluser]mikevu[/eluser]
I think this is a issue of upload of CI. I have met face the problem with file doc. However, I have completed fixing the bug for my project, so the solution is not support for CI, I am sorry.
Have a GREAT day




Theme © iAndrew 2016 - Forum software by © MyBB