【问题标题】:File upload not working properly on my server文件上传在我的服务器上无法正常工作
【发布时间】:2013-09-19 08:40:01
【问题描述】:
    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 无效。为什么?

【问题讨论】:

  • upload_path 是否存在?有什么权限?
  • $config_file['upload_path'] = 'img/blog/'; -> $config_file['upload_path'] = '文档/博客/';两条路径都存在,权限为 777
  • 这很难以目前的形式回答,因为大部分逻辑都隐藏在 $this->upload 是一个实例的任何类中。你能把那节课的内容贴出来吗?

标签: php codeigniter file-upload


【解决方案1】:
 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;
            }
        }
    }

...希望我帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    相关资源
    最近更新 更多