2
votes

I am working in codeigniter framework.I want to upload doc or docx file.So i have write code like this:

$config['upload_path'] = './uploads/resume/';
$config['allowed_types'] = 'docx|doc|DOC|DOCX';

$this->upload->initialize($config);

if ( ! $this->upload->do_upload('resume'))
{
    print_r($error = array('error' => $this->upload->display_errors()));
}
else
{
    $upload = $this->upload->data();
    print_r($upload);exit;
}

Here, it shows and error like The filetype you are attempting to upload is not allowed. And file is not uploaded.

I have also modify mimes.php file and add

'doc'    =>    array('application/msword', 'application/vnd.ms-office'),
'docx'    =>    array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),

When I print $this->upload->data() then it shows file_type as application/vnd.oasis.opendocument.text

But, its not working.So how can I upload doc or docx file?

4
what is your CI version? - Abdulla Nilam
@Abdulla its 2.2.6 - Nisarg Bhavsar
did you load library?? - Abdulla Nilam
@Abdulla yes i have load library. - Nisarg Bhavsar

4 Answers

1
votes

Here I have created doc array in mimes.php like this :

'doc'    =>    array('application/msword', 'application/vnd.ms-office','application/vnd.oasis.opendocument.text')

and its working.

0
votes

I don't see "application/vnd.oasis.opendocument.text" in your array of allowed mime types.

0
votes

Don't forget max_size and allowed type to txt

$config['allowed_types']        = 'txt|doc|docx';
$config['max_size']             = 10000;

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

If still fails load OpenOffice extension too

$config['allowed_types'] = 'application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.text | application/vnd.oasis.opendocument.presentation | 
application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.ms-excel | application/vnd.openxmlformats-officedocument.presentationml.presentation | txt';
0
votes

Add the following to the mimes.php file

'binary/octet-stream'

for each office document type you want to support. Not an ideal solution but works for me.