File upload problems with CodeIgniter
I’ve been exploring CodeIgniter for a recent PHP project and I must say that I like what I see. With any framework there is a learning curve but CI is very easy to get up and running. I also like the fact that CI really encourages the of MVC for projects. If you have done a little PHP and want to explore the world of MVC CI is a great choice.
Anyway, after added an upload from to my project and testing it out with a few images I starting receiving the “The filetype you are attempting to upload is not allowed” error when attempting to upload a csv file. After digging around for a bit I found that CI uses a mimes.php file the application/config directory that controls which mime types are allowed for certain code. For csv they were about 10 different ones in the array. Since the error was so specific I figured my file must have the wrong mime type even though I saved it from Excel as a .csv. I used the bit of code below in my upload function in order to see my mime type.
$config[‘*’] = ‘csv’;
$data = array(‘upload_data’ => $this->upload->data());
$mimetype = $data[‘upload_data’][‘file_type’];
echo $mimetype;
After uploading my file I found that the mime type was text/plain and not csv. I added the text/plain option to my mimes.php csv array and whala!! Success! Hopefully this will help someone on the W (short for web).