codeigniter - When 2 different images are uploaded to 2 different folders,then the images are uploaded.but the thumbs are not created -


here controller function, please me create thumbs of both images. images uploaded folder. created function named resize create thumbs. that's given in controller.

public function add() {      $this->load->helper(array('form', 'url'));     $this->load->helper('file');     $this->load->library('form_validation');       $this->form_validation->set_rules('txtprdname', 'product name', 'trim|required|htmlspecialchars');     $this->form_validation->set_rules('sbprdcategory', 'product category', 'trim|required|htmlspecialchars');     $this->form_validation->set_rules('sbprduser', 'managing user', 'trim|required|htmlspecialchars');     $this->form_validation->set_rules('txtprdprofile', 'product profile', 'trim|required|htmlspecialchars');      if ($this->form_validation->run() == false) {          $data_view["error"] = "";          $this->load->view('moderator/templates/header');         $this->load->view('moderator/templates/sidebar');         $this->load->view('moderator/b2bproduct_add', $data_view);         $this->load->view('moderator/templates/footer');      } else {          // image uploading codes          $config['upload_path'] = 'assets/images/b2bproduct';         $config['allowed_types'] = 'gif|jpg|jpeg|png';         $config['max_size'] = '1000';         $config['max_width'] = '2024';         $config['max_height'] = '1768';         $config['overwrite'] = true;         $config['remove_spaces'] = true;          if (isset($_files['fileprdimage']['name'])) {             $config['file_name'] = substr(md5(time()), 0, 28) . $_files['fileprdimage']['name'];         }          $this->load->library('upload');          $this->upload->initialize($config);          if (!$this->upload->do_upload('fileprdimage')) {              //no file uploaded or failed upload              $error = array('error' => $this->upload->display_errors());          } else {              $dat = array('upload_data' => $this->upload->data());              $this->load->library('upload');             $this->upload->initialize($config);             $this->resize($dat['upload_data']['full_path'], 'assets/images/b2bproduct/thump/' . $dat['upload_data']['file_name'], 180, 400);         }          if (empty($dat['upload_data']['file_name'])) {             $prdimage = '';         } else {             $prdimage = $dat['upload_data']['file_name'];         }              // end image uploading codes         // logo uploading codes          $config['upload_path'] = 'assets/images/b2blogo';         $config['allowed_types'] = 'gif|jpg|jpeg|png';         $config['max_size'] = '1000';         $config['max_width'] = '2024';         $config['max_height'] = '1768';         $config['overwrite'] = true;         $config['remove_spaces'] = true;          if (isset($_files['fileprdlogo']['name'])) {             $config['file_name'] = substr(md5(time()), 0, 28) . $_files['fileprdlogo']['name'];         }          $this->load->library('upload');          $this->upload->initialize($config);          if (!$this->upload->do_upload('fileprdlogo')) {              //no file uploaded or failed upload              $error = array('error' => $this->upload->display_errors());          } else {              $dat1 = array('upload_data' => $this->upload->data());              $this->load->library("upload",$config);              $this->resize($dat1['upload_data']['full_path'], 'assets/images/b2blogo/thump/' . $dat1['upload_data']['file_name'], 180, 400);         }          if (empty($dat1['upload_data']['file_name'])) {             $prdlogo = '';         } else {             $prdlogo = $dat1['upload_data']['file_name'];         }          // end logo uploading codes                   $data = array(             'prd_name' => $this->input->post('txtprdname'),             'prd_category' => $this->input->post('sbprdcategory'),             'prd_user' => $this->input->post('sbprduser'),             'prd_profile' => $this->input->post('txtprdprofile'),             'prd_oem' => $this->input->post('rbtnprdoem'),             'prd_protype' => $this->input->post('rbtnprdprotype'),             'prd_image' => $prdimage,             'prd_ranktype' => $this->input->post('sbprdranktype'),             'prd_points' => $this->input->post('txtprdpoints'),             'prd_extrakey' => $this->input->post('txtprdextrakey'),             'prd_dated' => time(),             'prd_ipadd' => $_server['remote_addr']         );          $result_id = $this->b2bproduct_model->add($data);          if ($result_id) {              redirect(base_url() . 'moderator/b2bproduct/view/' . $result_id, 'refresh');          } else {              $data_view["error"] = "data can't insert due database error";              $this->load->view('moderator/templates/header');              $this->load->view('moderator/templates/sidebar');              $this->load->view('moderator/b2bproduct_add', $data_view);              $this->load->view('moderator/templates/footer');          }      }  } 

resize function

public function resize($source, $destination, $width, $height) {     $config['image_library'] = 'gd2';     $config['source_image'] = $source;     $config['create_thumb'] = true;     $config['maintain_ratio'] = true;     $config['width'] = $width;     $config['height'] = $height;     $config['new_image'] = $destination;     $this->load->library('image_lib', $config);     $this->image_lib->resize(); } 

first of loading library 2 times in function add please load 1 time @ top of function.

in resize use $this->image_lib->initialize($config) below

public function resize($source, $destination, $width, $height) {     $config['image_library'] = 'gd2';     $config['source_image'] = $source;     $config['create_thumb'] = true;     $config['maintain_ratio'] = true;     $config['width'] = $width;     $config['height'] = $height;     $config['new_image'] = $destination;     $this->load->library('image_lib');     $this->image_lib->initialize($config);     $this->image_lib->resize(); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -