文件上传错误codeIgniter

error in file uploading codeIgniter

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

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

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

希望对您有所帮助:

您的 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

我想你错过了这一行。

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

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


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

$this->load->library('upload', $config);

if($this->上传->do_upload('image_file')) {

    $filename = $this->upload->data('file_name');
    echo  $filename;die;
}
else
{
    print_r($this->upload->display_errors());
    die;
}