文件上传在我的服务器上无法正常运行

时间:2013-09-14 22:24:05

标签: php codeigniter file-upload

    function upload_cover(){
        $config_cover['upload_path'] = 'img/blog/';
        $config_cover['allowed_types'] = 'gif|jpg|png|tif';
        get_instance()->load->library('upload', $config_cover);
        if($this->upload->do_upload('myFile') )
        {
            $upload_data = $this->upload->data();
            $path = 'img/blog/'.$upload_data['file_name'];
            return $path;
        }
    }
    function upload_file(){
        $config_file['upload_path'] = 'img/blog/';
        $config_file['allowed_types'] = 'doc|docx|pdf|txt|xls|xlsx|ppt|pptx';
        $this->upload->initialize($config_file);
        if ($_FILES['myDoc']) {
            if($this->upload->do_upload('myDoc'))
            {
                $upload_data = $this->upload->data();
                $path = 'document/blog/'.$upload_data['file_name'];
                return $path;
            }
        }
    }

此代码在我的计算机上正常运行,但当我在我的服务器上部署时,只有upload_cover有效,而不是upload_file。为什么呢?

1 个答案:

答案 0 :(得分:0)

 function upload_file(){
        $config_file['upload_path'] = 'img/blog/';
        $config_file['allowed_types'] = 'doc|docx|pdf|txt|xls|xlsx|ppt|pptx';

        get_instance()->load->library('upload', $config_file);// try to add this
        $this->upload->initialize($config_file);
        if ($_FILES['myDoc']) {
            if($this->upload->do_upload('myDoc'))
            {
                $upload_data = $this->upload->data();
                $path = 'document/blog/'.$upload_data['file_name'];
                return $path;
            }
        }
    }

...希望我帮助