Reputation: 956
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?
Upvotes: 2
Views: 5734
Reputation: 1
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.
Upvotes: 0
Reputation: 38584
Don't forget
max_size
and allowed type totxt
$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';
Upvotes: 0
Reputation: 956
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.
Upvotes: 1
Reputation: 1874
I don't see "application/vnd.oasis.opendocument.text" in your array of allowed mime types.
Upvotes: 0