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条)

相关推荐 更多相似问题