Uploading a csv into Codeigniter

后端 未结 6 1091
醉话见心
醉话见心 2020-11-28 13:45

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 t

相关标签:
6条回答
  • 2020-11-28 14:04

    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')
    
    0 讨论(0)
  • 2020-11-28 14:06

    I tried many things to upload csv file in codeigniter:-

    i add mime type ( application/vnd.ms-excel ) to mime type file but the mean issue is codeigniter will only accept file name userfile. if you will set file name userfile then it works.

    I think there might be another way but i unable to find that.

    0 讨论(0)
  • 2020-11-28 14:10

    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.

    0 讨论(0)
  • 2020-11-28 14:13

    I had the same problem uploading .csv files. I solved it by determining the mime type by using file -I file.csv in the OS X Terminal. It reported that the mime type was 'text/plain' so I added that to the config/mimes.php file.

    0 讨论(0)
  • 2020-11-28 14:14

    first in allowed types just type 'csv'

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

    second go to /config/mimes.php and change the 'csv' array element as follows:

     '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'
     ),
    
    0 讨论(0)
  • 2020-11-28 14:22

    -- Codeigniter 2.2.0 --

    I did a quick debug on the Upload library and I have found out that sometimes the same source code running on different servers will identify the same CSV file having different file type (i.e. Server 1 identify the CSV file as: application/vnd.ms-excel but Server 2 identify the same CSV file as: text/x-c).

    My fix was to add, in application/config/mimes.php, the file type that is identified by the server where was the issue. Hence, my csv array from mimes.php file looks like: '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', 'text/x-c').

    0 讨论(0)
提交回复
热议问题