dthhlf1777 2018-07-24 12:28
浏览 49
已采纳

文件上传codeIgniter中的错误

Below is the code for my controller....

public function do_upload()
    {

        $config['upload_path']='./upload/';
        $config['allowed_types']='gif|jpg|png';
        $this->load->library('upload',$config);
        $this->upload->do_upload('image_file');
        if($this->upload->do_upload('image_file'))
        {
            $filedata = $this->upload->data();
            $filename = $filedata['raw_name'].$filedata['file_ext'];

            return $filename;
        }

    }

After this call this function where You want to make this upload...in controller

    if($_FILES)
                    {
                        $this->do_upload();
                    }

but file is not uploaded.......why?

  • 写回答

2条回答 默认 最新

  • doubai9014 2018-07-24 12:59
    关注

    Hope this will help you :

    Your do_upload method should be like this :

    public function do_upload() 
    {
        $config['upload_path'] = './upload/';
        $config['allowed_types']='gif|jpg|png';
        $this->load->library('upload', $config);
        if($this->upload->do_upload('image_file'))
        {
            $filename = $this->upload->data('file_name');
            echo  $filename;die;
        }
        else
        {
            print_r($this->upload->display_errors());
            die;
        }
    }
    

    UPDATE :

    set upload_max_filesize in your php ini greater than 2MB,

    if it is wamp just follow :

    click on wamp => php => php settings => upload_max_filesize

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效