Welcome Guest, Not a member yet? Register   Sign In
howto upload 3 files
#1

[eluser]Mitja[/eluser]
How to upload 3 files and validate each of them.


If i try like
Code:
if (!$this->upload->do_upload($field_name))
            {                
                $data['error_pdf1'] = $this->upload->display_errors('<div class="warning">', '</div>');    
                $this->load->view('admin/content_add', $data);
            }    
            else
            {  
                $uploads = $this->upload->data();
                        
                $data_insert = array(
                    'title' => $uploads['orig_name'] ,
                    'pdf_name' => $uploads['orig_name'] ,
                    'content_Id' => $new_id
                );
                      
                $this->db->insert('pdf', $data_insert);
            
            }  
            
            if (!$this->upload->do_upload('pdf2'))
            {                
                $data['error_pdf2'] = $this->upload->display_errors('<div class="warning">', '</div>');    
                $this->load->view('admin/content_add', $data);
            }    
            else
            {  
                $uploads = $this->upload->data();
                        
                $data_insert = array(
                    'title' => $uploads['orig_name'] ,
                    'pdf_name' => $uploads['orig_name'] ,
                    'content_Id' => $new_id
                );
                      
                $this->db->insert('pdf', $data_insert);
            }  
            
            if (!$this->upload->do_upload('pdf3'))
            {                
                $data['error_pdf3'] = $this->upload->display_errors('<div class="warning">', '</div>');    
                $this->load->view('admin/content_add', $data);
            }    
            else
            {  
                $uploads = $this->upload->data();
                        
                $data_insert = array(
                    'title' => $uploads['orig_name'] ,
                    'pdf_name' => $uploads['orig_name'] ,
                    'content_Id' => $new_id
                );
                      
                $this->db->insert('pdf', $data_insert);
            }

then i get 3 times page loeaded and not just once.
#2

[eluser]xwero[/eluser]
just put
Code:
$this->load->view('admin/content_add', $data);
below the ifs and you will be fine.

I recommend you do it in a loop instead of 3 hardcoded ifs
Code:
$fields = array('pdf1','pdf2','pdf3');

foreach($fields as field)
{
   if (!$this->upload->do_upload($field))
            {                
                $data['error_'.$field] = $this->upload->display_errors('<div class="warning">', '</div>');    
                
            }    
            else
            {  
                $uploads = $this->upload->data();
                        
                $data_insert = array(
                    'title' => $uploads['orig_name'] ,
                    'pdf_name' => $uploads['orig_name'] ,
                    'content_Id' => $new_id
                );
                      
                $this->db->insert('pdf', $data_insert);
            }
}

$this->load->view('admin/content_add', $data);
This way you only have to remove an array value instead of a whole control structure.
#3

[eluser]Mitja[/eluser]
Thx for reply.

Still one problem.

The upload path does not appear to be valid.
The upload path does not appear to be valid.
The upload path does not appear to be valid.

instead of once write 3 times
#4

[eluser]xwero[/eluser]
It probably has to do with the settings that are reset at the end of the do_upload method. If you keep the same setting for the files you can do
Code:
$fields = array('pdf1','pdf2','pdf3');

foreach($fields as field)
{
   $this->upload->initialize($config);
   if (!$this->upload->do_upload($field))
   // rest of the code




Theme © iAndrew 2016 - Forum software by © MyBB