Question

    $this->load->library('upload');

    $file_config = array(
        'upload_path' => $dir,
        'allowed_types' => 'csv',
        'file_name' => strtoupper($this->input->post('class_name')) . '.csv',
        'overwrite' => TRUE,
        'max_size' => 2048,
        'max_filename' => 128,
        'remove_spaces' => FALSE
    );
    $this->upload->initialize($file_config);
    // DEBUG
    if (!$this->upload->do_upload('file'))
        echo $this->upload->display_errors();
    else
        echo 'UPLOADED.';

For some reason, if I put 'allowed_types' => '*',, it accepts it and it works just fine. but if I instead wanted only csv files: 'allowed_types' => 'csv', and when I upload a csv file, it outputs an error: The filetype you are attempting to upload is not allowed.

How can I fix this without letting all types of files upload *, and instead only let csv files upload?

Was it helpful?

Solution

The Codeigniter documentation says to use the files MIME type, the MIME type of CSV is "text/csv" so use that instead of just "csv". http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top