Welcome Guest, Not a member yet? Register   Sign In
Problem with multiple image uploading along with other fields using a single form...
#1

[eluser]Roy MJ[/eluser]
Hi everyone,

Ive got a problem with multiple image uploading. I have done multiple image uploading separately. But with other fields also included in the same form ,i have stumbled upon a road block... Can anyone help me with this problem..??

This is the code for multiple image upload...
Code:
function manage_image(){
    $data['image'] = $this->Homepage_model->select_image();
        if($this->input->post('Submit')){
           for($i=1;$i<=6;$i++)
            {    
               if($_FILES['photo_'.$i]['name']!=''){
                   //upload thumbnail
                    $config = array();
                    $config['upload_path'] = absolute_path().'flashimages/';
                    $config['allowed_types'] = 'png';
                    $config['file_name'] = '0'.$i;
                    $config['max_size']    = '500';
                    $config['overwrite'] = 'TRUE';    
                    $this->load->library('upload');
                    $this->upload->initialize($config);    
                    if ( ! $this->upload->do_upload('photo_'.$i))
                    {
                        $data['alert'] = $this->upload->display_errors();                        
                        $this->load->view('admin/homepage/add_image', $data);
                    }    
                    else
                    {
                        $upload_data = $this->upload->data();
                        
                        $filename = $upload_data['file_name'];
                        
                        $width = $upload_data['image_width'];
                        $height = $upload_data['image_height'];
                        $config1 = array();
                        $this->load->library('image_lib');
                        $config1['source_image'] = absolute_path().'flashimages/'.$filename;
                        
                        if($width>1){
                            //resize image
                            $sizes = array('width' => $width, 'height' => $height, 'new_width' => 355, 'new_height'    => 194);
                            $newsize = array();
                            $newsize = $this->image_lib->size_calculator($sizes);
                            $config1['maintain_ratio'] = TRUE;
                            $config1['width'] = $newsize['new_width'];
                            $config1['height'] = $newsize['new_height'];
                            $this->image_lib->initialize($config1);
                            $this->image_lib->resize();
                            $this->image_lib->clear();
                        }
                        $config1['maintain_ratio'] = FALSE;
                        $config1['width'] = 355;
                        $config1['height'] = 194;
                        $config1['create_thumb'] = TRUE;
                        $config1['thumb_marker'] = 'thumb_';
                        $this->image_lib->initialize($config1);
                        $this->image_lib->resize();
                        $this->Homepage_model->save_image('photo_'.$i,$filename);
                        $data['alert'] = 'image uploaded';
                    }
                }
            }
            $data['image'] = $this->Homepage_model->select_image();
            $this->load->view('admin/homepage/add_image',$data);
        }else{
            $this->load->view('admin/homepage/add_image',$data);
        }    
    }


This is the controller for normal form

Code:
function add(){
        //if data submitted ' '
        if($this->input->post('Submit')){
        
            $config = array(
                           array('field'   => 'product_name','label'   => 'Product Name', 'rules'   => 'required')
                           );
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin/product/add');
            }
            else{
            
                if($_FILES['pdf']['name']!=''){
                   //upload thumbnail
                    $config = array();
                    $config['upload_path'] = absolute_path().'files/';
                    $config['allowed_types'] = 'pdf';
                    $config['max_size']    = '1536';
                    $this->load->library('upload', $config);    
                    if ( ! $this->upload->do_upload('pdf'))
                    {
                        $data['alert'] = $this->upload->display_errors();                        
                        $this->load->view('admin/product/add', $data);
                    }    
                    else
                    {
                        $upload_data = $this->upload->data();
                        $filename = $upload_data['file_name'];
                        $this->Product_model->save('Add',$filename );
                        redirect('/admin/product/index');
                    }
                }else{
                    $this->Product_model->save('Add', '');
                    redirect('/admin/product');
                }
            
            }
        }else{
                $this->load->view('admin/product/add');
        }    
    }


Can anyone tell me how to integrate the two in the same function...??
The problem comes with the loop. Please help...




Theme © iAndrew 2016 - Forum software by © MyBB