在codeigniter上传图片问题

时间:2011-02-22 10:07:48

标签: codeigniter

朋友们,我想在两个不同的位置上传两张图片但是仍然可以在同一个地方上传。请帮忙

//upload images
        //some $config vars for image
        $config['upload_path'] = './images/articles';
        $config['allowed_types'] = 'gif|jpg|jpeg|png|mp3|wav';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';

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

        //upload main image
        if(!$this->upload->do_upload('a_image')){
            $e = $this->upload->display_errors();
            //print_r($e);
        }

        $image = $this->upload->data();
        if($image['file_name']){
            $data['a_image'] = "images/articles/". $image['file_name'];
        }

        unset($config);

        //now upload thumb
        //some $config vars for thumb
        $config['upload_path'] = './images/articles/thumb';
        $config['allowed_types'] = 'gif|jpg|jpeg|png|mp3|wav';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';    
        $this->load->library('upload', $config);


        //upload thumbnail
            if(!$this->upload->do_upload('a_thumbnail')){
            $this->upload->dispaly_errors();    
        }   

1 个答案:

答案 0 :(得分:2)

第二次,打电话

$this->upload->initialize($config)

而不是

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

此外,您可以重复使用$config数组,只更改需要更改的值...