Has anyone else had trouble uploading a csv file into Codeigniter? I'm getting a pretty annoying "The filetype you are attempting to upload is not allowed." error, even though I've quite explicitly set the upload type. Here's my code (should be fairly standard stuff):
function doUpload() {
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'text/plain|text/csv|csv';
$config['max_size'] = '5000';
$config['file_name'] = 'upload' . time();
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
$file_info = $this->upload->data();
$csvfilepath = "uploads/" . $file_info['file_name'];
$this->addfromcsv($csvfilepath);
}
}
I tried to cover all the bases in my allowed types - maybe I missed one? Thanks for any help with this!
I got it working by adding cbrandolino's suggested mimetypes to the config/mimes.php (great tip jljohnstone). So the csv property of my $mimes looks like this now:
'csv' => array('application/vnd.ms-excel', 'text/anytext', 'text/plain', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel')
Unluckily there is no official specification, so there's quite a lot of them: the most popular among those that are missing are,
text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext
It's highly unlikely you'll meet another one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With