文件上载codeIgniter时出错

kmb7vmvb  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(149)

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

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

但文件未上传.......为什么?

wlsrxk51

wlsrxk511#

希望这对您有所帮助:

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

r8uurelv

r8uurelv2#

我想你没听到这句台词。
上传文件的路径为:
$config [允许的类型]='gif| jpg格式|png“;

$this-〉上载-〉初始化($config);

$this-〉加载-〉库('上载',$config);
如果($this-〉上传-〉do_upload('图像文件')){

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

相关问题