2

I'm using codeigniter upload class and I'm trying to upload a csv file.

Here is my PHP code :

public function upload(){
    $config['upload_path']      = './csv/';
    $config['allowed_types']    = 'csv';
    $config['max_size']         = 10240;
    $this->upload->initialize($config);
    if (!$this->upload->do_upload('file')){
        echo "<pre>"; 
        print_r($this->upload->data()); 
        echo "</pre>"; 
        die();
        $this->session->set_flashdata('upload_error', $this->upload->display_errors());
        redirect('/Customers');
    }else{
        $this->session->set_flashdata('upload_success', 'Customer list successfully uploaded!');
        redirect('/Customers');
    }   
}

when I upload my csv file I get :

Array
(
    [file_name] => mayfile.csv
    [file_type] => text/x-fortran
    [file_path] => /home/public_html/....
    [file_ext] => .csv
    [file_size] => 7842
    [is_image] => 
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)

The type should be text/csv not text/x-fortran why is that happening?

This is a preview of the csv file data I have uploaded: [CSV uploaded[1]

Thank you

oussama kamal
  • 1,027
  • 2
  • 20
  • 44

1 Answers1

4

I believe this is a duplicate of: Detecting a mime type fails in php

In it, the answer states:

Apparently, it scans the start of the file looking for lines that begin with a single C letter plus spaces, which seem to be a Fortran style comment. Thus the false positive:

somecolumn;
C F;

I would recommend reading that answer for further instructions. In this particular case, I'd recommend checking the extension if the mime is returned as Fortran to ensure it's not a CSV. Unfortunately there isn't a cleaner way that I know of.

Community
  • 1
  • 1
Mikel Bitson
  • 3,583
  • 1
  • 18
  • 23