Welcome Guest, Not a member yet? Register   Sign In
Multiple file upload problem
#1

[eluser]zsela[/eluser]
Hi Everyone,

I am pretty new at coding with CodeIgniter, but I pretty much enjoy it. However I ran into a problem on the other day which is related to multiple file uploading. My code doesn't want to work, when I want to upload multiple pictures and some additional input fields at the same time. I use an array as name for the pictures, but at the controller side the array seems to be empty. What is strange is that the $_FILE array does contain the uploaded pictures.

Here is the relevant part of the view:

Code:
$attributes_pic = array('id' => 'upload_real_pic_form');
                        echo form_open_multipart('realestate/upload_photo/' . $page_data['realestate_ID'], $attributes_pic);

                                        echo '<td class="centerMediumCol" colspan="2">';
                                        echo '&lt;input type="file" name="pic[' . $i . ']" id="pic[' . $i . ']" /&gt;';
                                                if (isset($page_data['pic' . $i . '_error']) && $page_data['pic' . $i . '_error']) {
                                                        
                                                        echo '<br /><br />';
                                                        foreach ($page_data['pic' . $i . '_error'] as $v) {
                                                                echo $v;
                                                        }
                                                        
                                                }

And here is the controller:

Code:
$config['upload_path'] = './images/uploads/realestates/';
      $config['overwrite'] = TRUE;
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '1024';
      $config['max_width']  = '4000';
      $config['max_height']  = '3000';
      
      $this->load->library('upload');
      
      $i = 1;
      $success = 0;
      foreach($this->upload->data('pic') as $k => $image) {
      
       $index = ($i < 10)?'0'.$i:$i;
       $config['file_name'] = 'realestate_' . $realestate_ID . '_' . $index;
       $this->upload->initialize($config);
      
       echo $config['file_name'];
      
       if (!$this->upload->do_upload($image)) {
        
        // hiba volt a feltöltésnél
        $page_data['pic' . $k . '_error'] = array('upload_error' => $this->upload->display_errors('<p class="error">', '</p>'));
        
        $page_data['realestate_ID'] = $realestate_ID;
        $page_data['pic_limit'] = $data['user_limit_pic'];      
        $this->load->view('realestate/upload_picture', array('page_data' => $page_data));
        
       } else {
        
        $pr = ($primary == $k)?1:0;
        
        $pic_data = array('upload_data' => $this->upload->data());
        $this->Realestate_model->del_realestate_pictures($realestate_ID);
        $this->Realestate_model->upload_realestate_pictures($realestate_ID, $pic_data['upload_data']['file_name'], $type[$i], $description[$i], $pr);
        
        $success = 1;
        
       }
      
       $i++;
      
      }

If I printout $this->upload->data('pic') it is an empty array.
What do I do wrong?

Thanks for your replies in advanced!


Messages In This Thread
Multiple file upload problem - by El Forum - 11-15-2012, 03:34 PM
Multiple file upload problem - by El Forum - 11-15-2012, 03:56 PM
Multiple file upload problem - by El Forum - 11-15-2012, 04:04 PM
Multiple file upload problem - by El Forum - 11-15-2012, 04:17 PM
Multiple file upload problem - by El Forum - 11-15-2012, 04:20 PM
Multiple file upload problem - by El Forum - 11-19-2012, 03:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB