Codeigniter上传不接受.doc文件

时间:2012-05-02 15:21:37

标签: codeigniter file-upload mime-types

我尝试上传时出现以下错误:

“不允许您尝试上传的文件类型。”。

这是我的.doc mime:

'doc'=>阵列( '应用程序/ msword', '应用程序/文档', '申请/文本', '应用/ vnd.msword', '应用程序/字', '应用/ WINWORD', '应用程序/ vnd.msword', '应用程序/ x-msw6', '应用程序/ x-MSWORD'),

正如你所看到的,我已经尝试通过添加更多的哑剧来弥补它。我不知道问题是什么......文件是.doc。请注意,上传pdf确实有效!我也在使用mac。

这是我的代码:

$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;
 }
} 

3 个答案:

答案 0 :(得分:3)

我做了print_r($ fileData);找出.doc file_type是什么。它是“text / plain”,所以我把它添加到我的mimes.php中它解决了我的问题。

答案 1 :(得分:0)

更改扩展程序的顺序。

答案 2 :(得分:0)

将此添加到配置----&gt; 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'),
相关问题