在codeigniter中上传docx文件

时间:2018-08-15 17:21:57

标签: php codeigniter codeigniter-upload

mimes.php

        'doc'   =>  array('application/msword', 'application/vnd.ms-office'),
        'docx'  =>  array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
        'dot'   =>  array('application/msword', 'application/vnd.ms-office'),
        'dotx'  =>  array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
        'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
        'word'  =>  array('application/msword', 'application/octet-stream'),

var_dump给出以下响应

string(24)"application/octet-stream"

这是我的一些控制器代码

        if(!empty($_FILES['file_name']))
                        {
                            // Profile Pic upload
                            $config = array();
                            $config['upload_path']           = 'uploads/file/'; 
                            $config['allowed_types']         = 'gif|jpg|png|jpeg|pdf|csv|txt|doc|docx|rar|zip|svg|xml|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx|CSV|TXT|SVG'; 
                            $config['max_size']              =10000; 
                            $config['max_width']             = 1024; 
                            $config['max_height']            = 1024; 
                            $config['file_ext_tolower']      = true;
                            $this->load->library('upload', $config, 'profilepic');
                            $this->profilepic->initialize($config);

                            if(!$profile_pic = $this->profilepic->do_upload('file_name')) 
                            {
                                $this->session->set_flashdata('message', $this->upload->display_errors());
                            }
                            else 
                            {
                                 $imgname = $this->profilepic->data();
                                 $imgpath = 'uploads/file/'.$imgname['file_name'];
                                 $data['file_name'] = $imgpath;
                            }                       
                        }else{
                            $this->session->set_flashdata('message', 

'请 我尝试了所有可能的解决方案,但未能成功。请提出建议。

1 个答案:

答案 0 :(得分:1)

我错过了控制器中的docx,并在docx哑剧中添加了“ application / octet-stream”,从而解决了问题。感谢您的努力和时间。

相关问题