简体   繁体   English

文件上传codeIgniter出错

[英]error in file uploading 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?但是文件没有上传......为什么?

Hope this will help you :希望对你有帮助 :

Your do_upload method should be like this :你的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;
    }
}

UPDATE :更新

set upload_max_filesize in your php ini greater than 2MB,在你的 php ini 中set upload_max_filesize大于 2MB,

if it is wamp just follow :如果它是wamp ,请遵循:

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

I think you missed this line.我想你错过了这条线。

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

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


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

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

if($this->upload->do_upload('image_file')) { if($this->upload->do_upload('image_file')) {

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM