0

I want to upload two images with my given name

 $config['upload_path'] = '/path/to/file';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';
        $config['file_name'] ='logo1_'.$_POST['name'];
        $config['max_width']  = '0';
        $config['max_height']  = '0';
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload('image1'))
        {...}
        else
        {
            $data = $this->upload->data();
        }
$config2['upload_path'] = '/path/to/file';
        $config2['allowed_types'] = 'gif|jpg|png';
        $config2['max_size'] = '0';
        $config2['file_name'] = 'logo2_'.$_POST['name'];
        $config2['max_width']  = '0';
        $config2['max_height']  = '0';
        $this->load->library('upload', $config2);
        if ( ! $this->upload->do_upload('image2'))
        {...}
        else
        {
            $data = $this->upload->data();
         }

My first image correctly saved in my folder with the name logo1_myname but my second image dosen't save as logo2_myname it save as logo1_myname1 What is wrong with my code ?

Saeed Masoumi
  • 8,746
  • 7
  • 57
  • 76
  • i think this link is your answer http://stackoverflow.com/questions/4528116/codeigniter-image-upload-will-only-upload-to-one-dir#4537964 – Majid Golshadi Jul 26 '14 at 14:37

1 Answers1

1

Change

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

to

$this->upload->initialize($config2);

Since the class has already been loaded codeigniter won't load it again.

Hope this helps.

Rwd
  • 34,180
  • 6
  • 64
  • 78