• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed with multi upload, extra text fields and database

Hi again everyone,

I do know that this question have been asked million times before, but I just can't find way to make this thing work.

So this is the scenario :
I am building a classified ad site, and I need to be able to make a form with 3 images and a few other fields with information and than to store the information in to the database. After searching more than 3 hours on google I've finally decided to ask you guys for a good workaround.
The below controller code has been taken also from this forum, but I need somehow to make this code to also insert the other fields into the database, not only the images.

Controller :

$config['upload_path'] = './uploads';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '2048'; //2 meg
            $config['encrypt_name']    = TRUE;
            $this->load->library('upload', $config);
            //Upload error flag
            $error = FALSE;

            foreach($_FILES as $key => $value)
                if( !empty($value['name']))
                    if ( $this->upload->do_upload($key) )
                        $uploaded = $this->upload->data();

                        //Creat Thumbnail
                        $config['image_library'] = 'GD2';
                        $config['source_image'] = $uploaded['full_path'];
                        $config['create_thumb'] = TRUE;
                        $config['thumb_marker'] = '_tn';
                        $config['master_dim'] = 'width';
                        $config['quality'] = 75;
                        $config['maintain_ratio'] = TRUE;
                        $config['width'] = 175;
                        $config['height'] = 175;


                        $imagename = $uploaded['file_name'].'_tn'.$uploaded['file_ext'];
                        $timestamp = time();

                        $this->db->set('file', $imagename);
                        $error = TRUE;
//If we have some error...
if($error) $this->session->set_flashdata('notice', '<div class="error icon"><ol>'.$this->upload->display_errors('<li>','</li>').'</ol></div>');

else $this->session->set_flashdata('notice', '<p class="success icon">¬°Success!</p>');

//Call the view

The real problem with this controller is that if I am trying to insert also the text field information when I am inserting the images, because it's in the foreach loop, it will insert the information 3 times.
I just can't find the logic to this operation correct.

My ads table is looking like this :

id title content someotherfield1 someotherfield2 image1 image2 image3

If there is any tutorial already posted somewhere please point me to it, because as I said above, I've searched for a workaround for more than 3 hours, and I was not successful.

Thanks in advance and sorry for my bad english.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme ¬© 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.