无法使用上载库将docx文件上载到服务器


Cannot upload docx files to server using upload library

当我尝试使用codeignitor上传功能将docx文件上传到服务器时,会出现"无效文件类型"错误,但它在本地服务器以及pdf、doc和图像文件中都能正常工作。

下面是我的文件上传脚本。

我使用ajaxuploader上传文件

<script>
    //.......................FILE UPLOAD ...........................................
    $(function(){ 
        var btnUpload=$('#nefile');
        new AjaxUpload(btnUpload, {
            action: '<?php echo site_url('userdashboard/saveabstractdocument'); ?>',
            name: 'file',
            onComplete: function(file, response){
                if(response)
                {
                    if(response == 1){

                        $('#abstractdoc').css('display','none');
                        $('#abstractval').css('display','block');

                    }else{

                        //$('#metaimgval_error').html("");
                        $("#val").val(response);
                        $('#abstractval').css('display','none');
                    }

                } else
                {
                }
            }
        }); 
    });
    //.......................FILE UPLOAD ENDS...........................................
</script>

下面是我的控制器功能

 function saveabstractdocument() { 
        $abstractfile = $_FILES["file"]["name"];
        $filenme = $_FILES["file"]["name"];
        $ext = explode(".", $filenme);
        $cnt = count($ext) - 1;
        $filenme = date("m") . date("d") . date("Y") . time() . "." . $ext[$cnt];
        $fil = date("m") . date("d") . date("Y") . time();
        $config['upload_path'] = './uploads/abstract/';
        $config['file_name'] = $fil;
        $config['allowed_types'] ='pdf|doc|docx';
        $config['max_size'] = '';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload("file")) {
            $data["err"] = array('error' => $this->upload->display_errors());
           // print_r($this->upload->display_errors());exit;
            echo 1;
        } else {
            $this->load->library('session');
            $datafile = array
                (
                'fname' => $filenme
            );
            $this->session->set_userdata($datafile);
            echo $abstractfile;
        }
    }

为什么不在视图中这样使用。。。

<input type="file" name="file"/>

或者在你的问题中,无效的类型可能不包括在你的mimes.php文档、pdf、docx中并且您的$config['max_size']='';如果你不愿意投入任何价值,你可以删除它。

这里还有我的上传文件的样本

$config['upload_path']   = './files/contracts-csv/'; 
                $config['allowed_types'] = 'csv';   
                $config['max_size']      = '4096';      
                $config['overwrite']     =  TRUE;
                $this->load->library('upload', $config);
                $this->upload->display_errors('', '');
                if (!$this->upload->do_upload("csv_file")) {
                      echo $this->upload->display_errors(); die();
                      $this->data['error'] = array('error' => $this->upload->display_errors());
                } else {
                    $upload_result = $this->upload->data(); 
                    $pathfile = $upload_result['full_path'];
                }

希望我能给你一个想法