Codeigniter upload not accepting .doc files
I'm getting the following error when I try to upload:
“The filetype you are attempting to upload is not allowed.”.
Here is my mime for .doc:
'doc' => array('application/msword','application/doc','appl/text','application/vnd.msword','application/word','application/winword','application/vnd.ms-word','application/x-msw6','application/x-msword'),
As you can see I already tried to make up for it by adding more mimes. I have no idea what the problem can be… the file is .doc. Note that uploading pdf's do work! I'm also using a mac.
Here is my code:
$sntError = $this->uploadFile($id,'notes','doc|pdf|docx');
private function uploadFile ($id,$input,$extensions) {
$this->load->library('upload');
$config['allowed_types'] = $extensions;
$config['upload_path'] = './upload/sermon/'. $input;
$config['file_name'] = $input .'-'. $id;
$config['max_size'] = '10000';
$config['overwrite'] = true;
$this->upload->initialize($config);
$uploaded = $this->upload->do_upload($input);
$errors = $this->upload->display_errors('<div class="error">', '</div>');
if (!$errors && $uploaded) {
$fileData = $this->upload->data();
$this->saveSermonAttachments($id,$input,$fileData['file_name']);
} else {
return $errors;
}
}
I did print_r($fileData); to figure out what the .doc file_type was. It was "text/plain," so I added that to my mimes.php and it solved my problem.
更改扩展的顺序。
将此添加到config ----> mimes.php
'doc' => 'application/msword',
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'word' => array('application/msword', 'application/octet-stream'),
链接地址: http://www.djcxy.com/p/45536.html