2

I'm having issues uploading a CSV file in codeigniter.

I am getting the error:

array(1) { ["error"] => string(64) "The filetype you are attempting to upload is not allowed." } 

Ok!!

but I am setting allowed_types like this:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$this->load->library('upload', $config);

and i have this in mimes.php:

'csv'   =>  array('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', 'text/plain'),

So any ideas why I am still getting this error?

$_FILES dump:

Array
(
    [name] => default questions.csv
    [type] => application/force-download
    [tmp_name] => /tmp/phpbkXxUd
    [error] => 0
    [size] => 5899
)
shyammakwana.me
  • 5,562
  • 2
  • 29
  • 50
frobak
  • 557
  • 2
  • 11
  • 30
  • Type `application/force-download` is a problem , file's is currpt , it does not have a valid format and mime type , to be declared csv file. fi you put `application/force-download` inside mime list for csv, then it will allow the file to be uploaded . but still `application/force-download` is being added from invalid header `content-disposition` , which should be a `content-disposition:attachment` – Arsh Singh Aug 02 '16 at 15:46
  • add `echo $this->upload->display_errors();` and post the complete Error – Abdulla Nilam Aug 02 '16 at 15:52
  • @Spartan That's the error I've posted to the top of the question? – frobak Aug 02 '16 at 15:56
  • `echo pathinfo($filename, PATHINFO_EXTENSION);` add file name with `$_file` and post the output – Abdulla Nilam Aug 02 '16 at 15:59
  • it throws an error on this `pathinfo($filename, PATHINFO_EXTENSION);` says $filename is wrong – frobak Aug 02 '16 at 16:05
  • replace` $filename` with `$_FILE['html_name_of the file']` – Abdulla Nilam Aug 02 '16 at 16:06
  • What file? controller/model/view/csv file? – frobak Aug 02 '16 at 16:07
  • there is an html part to upload file from view. AN dthere is name of that too. Add the name to this. Some thing like this ``. So $_FILE should be `$_FILE['pic']` – Abdulla Nilam Aug 02 '16 at 16:10
  • Ok yes already posted the value of $_FILE above – frobak Aug 02 '16 at 16:12
  • add like this `pathinfo($_FILE['add_your_file_name'], PATHINFO_EXTENSION);` – Abdulla Nilam Aug 02 '16 at 16:15
  • nope, doesnt like that, throws an error: Message: Undefined variable: _FILE – frobak Aug 02 '16 at 16:18
  • No no, do this.: `pathinfo($_FILES['name'], PATHINFO_EXTENSION);` – dmgig Aug 02 '16 at 18:06
  • Also, does your form element have this attribute? `enctype="multipart/form-data"` - something like this? `
    `
    – dmgig Aug 02 '16 at 18:08
  • This is an interesting question/answer as well, it might help you: http://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv – dmgig Aug 02 '16 at 18:11

1 Answers1

0

Try this

$config['allowed_types'] = '*';

This should work .Also check your upload.php or mimes.php. Use the latest one.

Diksha
  • 157
  • 2
  • 3
  • 9