【问题标题】:Codeigniter upload not accepting .doc filesCodeigniter 上传不接受 .doc 文件
【发布时间】:2012-05-12 02:28:56
【问题描述】:

我在尝试上传时收到以下错误:

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

这是我为 .doc 制作的 mime:

'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'),

如您所见,我已经尝试通过添加更多哑剧来弥补它。我不知道问题出在哪里……文件是 .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;
 }
} 

【问题讨论】:

  • 如果我没记错的话,data() 将返回文件的内容,即使上传因错误而终止。你能检查数据的内容并看到[file_type]吗?
  • 谢谢老兄。这帮助我找到了问题所在。显然文件类型是文本/纯文本。因此,我只是将其添加到已批准的 .doc 哑剧中。谢谢。

标签: codeigniter file-upload mime-types


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    更改扩展的顺序。

    【讨论】:

      【解决方案3】:

      将此添加到配置---->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'),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-07-10
        • 2015-06-05
        • 2012-10-02
        • 1970-01-01
        • 2010-11-01
        • 1970-01-01
        • 2015-12-26
        • 2013-04-01
        相关资源
        最近更新 更多