在codeigniter中文件上传无法正常工作

时间:2015-07-29 09:49:00

标签: php codeigniter

我使用代码点火器上传带有两个输入框的文件。 但我的代码没有上传两个文件我得到相同的文件两次。

请看一下我的代码 - :

public function do_upload(){

    foreach ($_FILES as $keys=>$values){

        if($keys == 'userfile1'){
            $config = array(
                        'upload_path' => "./uploads/",
                        'allowed_types' => "gif|jpg|png|jpeg|pdf",
                        'overwrite' => false,
                        'max_size' => "20480000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
                        'max_height' => "768000",
                        'max_width' => "1024000"
                        );
                $this->upload->initialize($config);
                $this->load->library('upload', $config);
                if($this->upload->do_upload())
                { $data = array('upload_data' => $this->upload->data());}
                else{   $error = array('error' => $this->upload->display_errors()); }
        }

        if($keys == 'userfile'){
            $config = array(
                'upload_path' => "./uploads/",
                'allowed_types' => "gif|jpg|png|jpeg|pdf",
                'overwrite' => false,
                'max_size' => "20480000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
                'max_height' => "768000",
                'max_width' => "1024000"
                );
            $this->load->library('upload', $config);
            if($this->upload->do_upload())
            {   $data = array('upload_data' => $this->upload->data());  }
            else{   $error = array('error' => $this->upload->display_errors()); }
        }

    }
控制器中的

{{1}}

1 个答案:

答案 0 :(得分:0)

请更改您的PHP代码并试一试

$this->upload->do_upload()

$this->upload->do_upload($field_name)

其中$field_name是您的输入名称属性。

请检查CodeIgniter's File Uploading Class