Search code examples
phpcodeigniteruploadmime-typesuploadify

Strange CodeIgniter file upload error


I've set up 'Uploadify' to upload files to my server where I process them with CodeIgniter's file upload library.

However, I think Uploadify changes the mime type of the files, or does something else weird which causes CodeIgniter to give a 'the file type is not allowed' error despite it being allowed.

E.g I've allowed JPEG files but when I upload them using Uploadify, I get that error.

Is there any workaround for this? Basically, I want only image uploads to be allowed, e.g .jpg, .jpeg, .bmp, .png. Do I have to manually check the extension of the files or is there any better option?


Solution

  • You're correct, uploadify uses the mime type application/octet-stream for most (all?) the files which it uploads. I think this is actually caused by Flash handling the uploading, but I'm not 100% sure.

    In your controller where you handle the upload, drop in a print_r($_FILES) and check out what the mime-type is, then just add it to your application/config/mimes.php file.

    So in your mimes.php file you'll probably have something like:

    'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),