0

CI version 2.1.4

I have created a file upload section in CI version 2.1.4 for text files. That is working fine for all normal text files. But if am trying to upload the text file which contains the word "program" unfortunately CI file validation showing unsupported file format. I tried to print the file type after adding the word "Program" but it is same as earlier(text/plain). I googled also but not getting any solution.

Please help me on this.

Config Variable

$config['allowed_attachment_types'] = 'gif|jpg|png|pdf|doc|docx|xlsx|word|xls|csv|txt|text';

Controller upload section

if ( ! $this->upload->do_upload('file')){
    $this->session->set_flashdata('growl_success', $this->upload->display_errors());
    redirect('/common/lists/edit/'.$id,'refresh');

} else {
    $uploaded = $this->upload->data();

    $data_attachment['id_list']     = $this->input->post('id_list');
    $data_attachment['filename']    = $uploaded['file_name'];
    $data_attachment['title']       = $this->input->post('attachment_title');
    $data_attachment['description'] = $this->input->post('attachment_description');
    $data_attachment['public_yn']   = $this->input->post('public_yn');
    $data_attachment['created_by']  = $this->ion_auth->user()->row()->id;
    $data_attachment['modified_by'] = $this->ion_auth->user()->row()->id;

    $this->attachment->update_attachment($this->input->post('id_attachment'),$data_attachment);
        redirect('/common/lists/edit/'.$id_list,'refresh');
}
Shemil R
  • 49
  • 6
  • show us your code? Its easier than predicting your code – Abdulla Nilam Jun 29 '16 at 12:38
  • Possible to add some code here? – krutssss Jun 29 '16 at 12:39
  • I have updated the question with code. – Shemil R Jun 29 '16 at 12:58
  • 1
    Is that same file being uploaded without `Program` word? – Poonam Jun 29 '16 at 13:10
  • @poonam Yes. with out that program word it is working. I created a text file with word program and tried. Then also it is not working. – Shemil R Jun 29 '16 at 13:21
  • please change the `$config['allowed_attachment_types'] to $config['allowed_types']` because there is no such config variable like **allowed_attachment_types** in file upload class. – Raj Jagani Jun 29 '16 at 13:23
  • @RajJagani I have created a new config for attachment section and assigned that to actual config. $config['allowed_types'] = $this->config->item('allowed_attachment_types'); If I am changing the wording (program) to anything else that file is uploading. – Shemil R Jun 29 '16 at 15:34
  • This is the answer for my question : http://stackoverflow.com/questions/2345899/fileinfo-and-mime-types-ive-never-heard-of We can add 'text/x-pascal' as file type – Shemil R Aug 18 '16 at 09:42

2 Answers2

0

I think you have to use -

$config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx|xlsx|word|xls|csv|txt|text';

instead of -

$config['allowed_attachment_types'] = 'gif|jpg|png|pdf|doc|docx|xlsx|word|xls|csv|txt|text';

please try this

Sorav Garg
  • 1,116
  • 1
  • 9
  • 26
0

I resolved the issue by adding 'text/x-pascal' type in the condition.

Shemil R
  • 49
  • 6