Welcome Guest, Not a member yet? Register   Sign In
$this->image_lib->resize() ...fails in a loop
#1

[eluser]potion[/eluser]
Three images are uploaded at once, but image_lib->resize succeeds only on first image. I suspect the cause is obvious, but I can't see it. Here's the function in the controller...

Code:
function update_project() {
    
    $this->load->model('projects_model');
    $record_id = $this->input->post('record_id');
    $record_data = array(
        'member_id'      => $this->input->post('member_id'),
        'title'          => $this->input->post('title'),
        'date'           => $this->input->post('date'),
        'info'           => $this->input->post('info'),
        'image1_caption' => $this->input->post('image1_caption'),
        'image2_caption' => $this->input->post('image2_caption'),
        'image3_caption' => $this->input->post('image3_caption')
    );
        
    for ($i = 1; $i <= 3; $i++) :  // upload the three pics

        $config['upload_path']   = './images/projects';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['remove_spaces'] = TRUE ;
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload("userfile"."$i")) :
            $success[$i] = false ;
            $error = array('error' => $this->upload->display_errors());
        else :
            $success[$i] = true ;
            $upload_data = $this->upload->data();
            $image_path = "images/projects/".$upload_data ['file_name'] ;

            $config['image_library']  = 'gd2';
            $config['source_image']   = $upload_data ['full_path'];
            $config['maintain_ratio'] = TRUE;
            $config['width']          = 150;
            $config['height']         = 100;
            $config['master_dim']     = 'width';
                
            $this->load->library('image_lib', $config);
            $this->image_lib->resize();
                
            switch ($i) :
                case 1: $record_data['image1_path'] = $image_path; break;
                case 2: $record_data['image2_path'] = $image_path; break;
                case 3: $record_data['image3_path'] = $image_path; break;
            endswitch;    
        endif ;    
    endfor ;
        
    $this->projects_model->update_project($record_id, $record_data);
    $this->edit_project();
}


Messages In This Thread
$this->image_lib->resize() ...fails in a loop - by El Forum - 05-20-2011, 10:27 AM
$this->image_lib->resize() ...fails in a loop - by El Forum - 05-20-2011, 11:54 AM
$this->image_lib->resize() ...fails in a loop - by El Forum - 05-20-2011, 02:28 PM
$this->image_lib->resize() ...fails in a loop - by El Forum - 05-20-2011, 02:37 PM
$this->image_lib->resize() ...fails in a loop - by El Forum - 04-23-2012, 02:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB