CodeIgniter将多个文件上载到多个目录

时间:2013-01-21 11:43:36

标签: codeigniter

        $configUpload = array();
        $configUpload['upload_path'] = './directory_1/';
        $configUpload['max_size'] = '6000';
        $configUpload['max_width'] = '9500';
        $configUpload['max_height'] = '9500';
        $configUpload['allowed_types'] = 'png|jpg|jpeg|gif|bmp';
        $this->load->library('upload',$configUpload);
        $upload_1 = $this->upload->do_upload('product_image');


        if($upload_1 === FALSE)
            $product_data = $this->upload->data();              
               continue;            
        $config = array();
        $config['upload_path'] = './directory_2/';
        $config['max_size'] = '5000';
        $config['max_width'] = '10000';
        $config['max_height'] = '10000';
        $config['allowed_types'] = 'png|jpg|jpeg|gif|bmp';
        $this->load->library('upload', $config);
        $upload = $this->upload->do_upload('product_image_2');

当我提交上传时,图像文件位于同一目录(directory_1)。

1 个答案:

答案 0 :(得分:3)

需要初始化您的课程  



$configUpload = array();
                    $configUpload['upload_path'] = 'uploads/canvas_uploads/upload_save/';
                    $configUpload['allowed_types'] = 'png|jpg|jpeg|gif|bmp';
                    $configUpload['file_name'] = date("Ymd") . time();
                    $configUpload['overwrite'] = true;
                    $this->load->library('upload', $configUpload);
                    $this->upload->initialize($configUpload);
                    $upload_1 = $this->upload->do_upload('file_input');


                    $config['upload_path'] = 'uploads/canvas_uploads';
                    $config['allowed_types'] = 'jpg|png|jpeg|gif|bmp|tif';
                    $config['file_name'] = date("Ymd") . time();
                    $config['overwrite'] = true;
                    $this->load->library('upload', $config);
                    $this->upload->initialize($config);
                  $this->upload->do_upload("file_input");