0

下面是我的控制器的代码....

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;
        }

    }

在此调用此函数后,您要在其中进行此上传...在控制器中

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

但是文件没有上传......为什么?

4

2 回答 2

0

我想你错过了这条线。

$config['upload_path']='./upload/';

$config['allowed_types']='gif|jpg|png';


$this->上传->初始化($config);

$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;
}
于 2018-07-28T07:33:53.883 回答
0

希望对你有帮助 :

你的do_upload方法应该是这样的:

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;
    }
}

更新

set upload_max_filesize在你的 php ini 中大于 2MB,

如果wamp只是跟随:

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

于 2018-07-24T12:59:21.310 回答