无法在codeigniter上传文档格式文件

时间:2015-04-01 06:00:34

标签: php codeigniter upload

$config['allowed_types'] = 'doc|Doc';

我只想上传文档格式文件,但是无法上传刚刚写好的文档格式文件不允许您尝试上传的文件类型。

为什么?

如何解决问题, 我添加了mimes文件,

'doc'   =>  'application/msword',
                'docx'  =>  array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
                'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),

1 个答案:

答案 0 :(得分:2)

你可以使用这个功能

 public function do_upload(){
          $this->config =  array(
                  'upload_path'     => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
                  'upload_url'      => base_url()."files/",
                  'allowed_types'   => "gif|jpg|png|jpeg|pdf|doc|xml|docx|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx",

                  'overwrite'       => TRUE,
                  'max_size'        => "1000KB",
                  'max_height'      => "768",
                  'max_width'       => "1024"   
                );
        $this->remove_dir($this->config["upload_path"], false);

        $this->ci->load->library('upload', $this->config);
        if($this->ci->upload->do_upload())
        {
            $this->ci->data['status']->message = "File Uploaded Successfully";
            $this->ci->data['status']->success = TRUE;
            $this->ci->data["uploaded_file"] = $this->ci->upload->data();
        }
        else
        {
            $this->ci->data['status']->message = $this->ci->upload->display_errors();
            $this->ci->data['status']->success = FALSE;
        }
    }