Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/serbaantik.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Products extends Admin_Controller { //this property is used for validating existing category title on call back edit category private $product_current_id; function __construct() { parent::__construct(); if (!in_array('product', $this->allowed_sections)) redirect('admin/dashboard'); $this->load->model('product_m'); $this->load->model('category_m'); $this->load->model('brand_m'); $this->load->library('image_lib'); $this->load->helper('form'); } //this is to list all products public function index() { //pagination in action. 100 results per page $this->load->library('pagination'); $config = array(); $this->load->helper('pagination_helper'); $config = pagination_format(); //function from helper file $config['base_url'] = base_url() . 'admin/products/index/'; $config['uri_segment'] = 4; if(isset($_POST['search_product'])) { $this->data['keyword'] = $this->input->post('keyword'); $config['per_page'] = 10000; $config['total_rows'] = $this->product_m->record_count_search_product($this->data['keyword']); $this->pagination->initialize($config); $this->data['products'] = $this->product_m->get_all_products_search_product($config['per_page'], $this->uri->segment($config['uri_segment']), $this->data['keyword']); } else { $config['per_page'] = 100; $config['total_rows'] = $this->product_m->record_count(); $this->pagination->initialize($config); $this->data['products'] = $this->product_m->get_all_products($config['per_page'],$this->uri->segment($config['uri_segment'])); } $this->data['use_pagination'] = 'yes'; //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function import_excel() { if(!$this->input->post('upload_excel')) { $this->session->set_flashdata('result', '<br><p style="background:red; color:white; padding:5px; font-weight:bold;">No file uploaded</p>'); redirect('admin/products'); } else { if (isset($_FILES['fileExcel']['name'])) { if($_FILES['fileExcel']['type'] != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') { $this->session->set_flashdata('result', '<br><p style="background:red; color:white; padding:5px; font-weight:bold;">File must be Excel with extension .xlsx</p>'); redirect('admin/products'); } $this->load->library(array('excel', 'session')); $path = $_FILES['fileExcel']['tmp_name']; $object = PHPExcel_IOFactory::load($path); foreach($object->getWorksheetIterator() as $worksheet) { $highestRow = $worksheet->getHighestRow(); break; } $this->db->trans_start(); //get category name & id for this sheet (column start from 0) $category_name = strtolower(trim($worksheet->getCellByColumnAndRow(0, 2)->getValue())); //get category id $category = $this->db->select('id_categories, category')->from('categories')->where('category', $category_name)->get()->row_array(); if(!is_null($category)) { //delete all previous data with the same category $deleted_products = $this->db->select('id_product')->from('category_product')->where('id_category', $category['id_categories'])->get()->result_array(); if(count($deleted_products) > 0) { foreach($deleted_products as $product) { $this->db->where('id_products', $product['id_product']); $this->db->delete('products'); $this->db->where('product_id', $product['id_product']); $this->db->delete('attribute_product'); $this->db->where('id_product', $product['id_product']); $this->db->delete('category_product'); } } $deleted_varians = $this->db->select('id')->from('varians')->where('category_id', $category['id_categories'])->get()->result_array(); if(count($deleted_varians) > 0) { foreach($deleted_varians as $varian) { $this->db->where('varian_id', $varian['id']); $this->db->delete('attributes'); $this->db->where('category_id', $category['id_categories']); $this->db->delete('varians'); $this->db->where('category_id', $category['id_categories']); $this->db->delete('varian_field_numbers'); } } //Start insert new data //adding products for($row = 2; $row <= $highestRow; $row++) { //add products $data_product = array( 'title' => trim($worksheet->getCellByColumnAndRow(1, $row)->getValue()), 'alias' => url_title(trim($worksheet->getCellByColumnAndRow(1, $row)->getValue())), 'meta_description' => 'Serba Antik Product - ' . ucwords(trim($worksheet->getCellByColumnAndRow(1, $row)->getValue())), 'categories' => $category['category'], 'sku' => trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()), 'stock' => trim($worksheet->getCellByColumnAndRow(3, $row)->getValue()), 'price' => (int) trim($worksheet->getCellByColumnAndRow(4, $row)->getValue()), 'martindale' => $worksheet->getCellByColumnAndRow(5, $row)->getValue(), 'frtest' => $worksheet->getCellByColumnAndRow(6, $row)->getValue(), 'description' => $worksheet->getCellByColumnAndRow(7, $row)->getValue(), 'washing_instruction' => $worksheet->getCellByColumnAndRow(8, $row)->getValue(), 'image1' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '.jpg', 'image2' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '_2.jpg', 'image3' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '_3.jpg', 'image4' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '_4.jpg', 'image5' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '_5.jpg', 'image6' => 'S' . trim($worksheet->getCellByColumnAndRow(2, $row)->getValue()) . '_6.jpg', ); for ($i = 9; $i <= 19; $i++) { if($worksheet->getCellByColumnAndRow($i, $row)->getValue() != '') { $data_product['varian' . ($i-8)] = trim($worksheet->getCellByColumnAndRow($i, 1)->getValue()); $data_product['attribute' . ($i-8)] = trim($worksheet->getCellByColumnAndRow($i, $row)->getValue()); //insert into table varian_field_numbers //check if category_id and varian exist $curr_var_nums = $this->db->select('id')->from('varian_field_numbers')->where('category_id', $category['id_categories'])->where('varian', trim($worksheet->getCellByColumnAndRow($i, 1)->getValue()))->get()->num_rows(); if($curr_var_nums == 0) { $this->db->insert('varian_field_numbers', array( 'category_id' => $category['id_categories'], 'varian' => trim($worksheet->getCellByColumnAndRow($i, 1)->getValue()), 'number' => $i-8 )); } } } $this->db->insert('products', $data_product); $product_id = $this->db->insert_id(); //add into category_product table $data_cat_product = array( 'id_product' => $product_id, 'id_category' => $category['id_categories'] ); $this->db->insert('category_product', $data_cat_product); //add varians here for ($col = 9; $col <= 19; $col++) { $varian_name = trim($worksheet->getCellByColumnAndRow($col, 1)->getValue()); if($varian_name !== '') { //check if existing varian exist $varian = $this->db->select('id')->from('varians')->where('varian', $varian_name)->where('category_id', $category['id_categories'])->get()->row_array(); if(is_null($varian)) { $insert_data = array( 'category_id' => (int) $category['id_categories'], 'varian' => $varian_name, ); //get last ordering number $current_priority = $this->db->select_max('priority')->from('varians')->where('category_id', $category['id_categories'])->get()->row()->priority; if($current_priority === null) { $insert_data['priority'] = 1; } else { $insert_data['priority'] = $current_priority + 1; } $this->db->insert('varians', $insert_data); $varian_id = $this->db->insert_id(); } else { $varian_id = $varian['id']; } //add attribute $attribute_name = trim($worksheet->getCellByColumnAndRow($col, $row)->getValue()); if($attribute_name !== '') { $attribute = $this->db->select('id')->from('attributes')->where('varian_id', $varian_id)->where('attribute', $attribute_name)->get()->row_array(); if(!$attribute) { $attribute_data = array( 'varian_id' => $varian_id, 'attribute' => $attribute_name, ); //get last ordering number $current_priority = $this->db->select_max('priority')->from('attributes')->where('varian_id', $varian_id)->get()->row()->priority; if($current_priority === null) { $attribute_data['priority'] = 1; } else { $attribute_data['priority'] = $current_priority + 1; } $this->db->insert('attributes', $attribute_data); $attribute_id = $this->db->insert_id(); } else { $attribute_id = $attribute['id']; } //insert into attribute_product $data_attribute_product = array( 'product_id' => $product_id, 'varian_id' => $varian_id, 'attribute_id' => $attribute_id ); $this->db->insert('attribute_product', $data_attribute_product); } } } } } $this->db->trans_complete(); $this->session->set_flashdata('result', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Import Products Success</p>'); redirect('admin/products'); } else { $this->session->set_flashdata('result', '<br><p style="background:red; color:white; padding:5px; font-weight:bold;">No excel file found</p>'); redirect('admin/products'); } } } //Add new product public function add() { $this->data['products'] = $this->product_m->get_new(); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); $this->data['brands'] = $this->brand_m->get_brands(); //validation in action //validation check in action $config = $this->product_m->rules; $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $image_filename1 = $this->image_processing($_FILES['image1'], 'image1'); $image_filename2 = $this->image_processing($_FILES['image2'], 'image2'); $image_filename3 = $this->image_processing($_FILES['image3'], 'image3'); $image_filename4 = $this->image_processing($_FILES['image4'], 'image4'); $image_filename5 = $this->image_processing($_FILES['image5'], 'image5'); $image_filename6 = $this->image_processing($_FILES['image6'], 'image6'); $data = $this->table_data_processing($image_filename1, $image_filename2, $image_filename3, $image_filename4, $image_filename5, $image_filename6); $product_id = (int) $this->product_m->add_product($data); $category_id = $this->input->post('category_id'); $data = array( 'id_product' => $product_id, 'id_category' => $category_id, ); $this->db->insert('category_product', $data); $data = array( 'categories' => $this->db->select('category')->from('categories')->where('id_categories', $category_id)->get()->row()->category, ); $this->db->where('id_products', $product_id); $this->db->update('products', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Added Successful</p>'); redirect('admin/products'); } $this->data['subview'] = 'admin/products/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to EDIT product in admin public function edit($id) { $this->db->select('id_products')->from('products')->where('id_products', $id); $count_product = $this->db->get()->num_rows(); if($count_product === 0) {show_404();} $this->data['products'] = $this->product_m->get($id); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); //get all chosen (active) categories $this->db->select('*')->from('category_product')->where('id_product', $id); $this->data['chosen_categories'] = $this->db->get()->result(); //get all brands $this->data['brands'] = $this->brand_m->get_brands(); //assign to properties, used for custom callback validation $this->product_current_id = (int) $this->data['products']->id_products; //get current brand id $this->db->select('brand_id')->from('products')->where('id_products', (int) $id); $products = $this->db->get()->row(); $this->data['brand_id'] = $products->brand_id; //validation check in action $config = $this->product_m->rules; $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $image_filename1 = $this->image_processing($_FILES['image1'], 'image1'); $image_filename2 = $this->image_processing($_FILES['image2'], 'image2'); $image_filename3 = $this->image_processing($_FILES['image3'], 'image3'); $image_filename4 = $this->image_processing($_FILES['image4'], 'image4'); $image_filename5 = $this->image_processing($_FILES['image5'], 'image5'); $image_filename6 = $this->image_processing($_FILES['image6'], 'image6'); $data = $this->table_data_processing($image_filename1, $image_filename2, $image_filename3, $image_filename4, $image_filename5, $image_filename6); $this->product_m->edit_product($id, $data); $category_id = $this->input->post('category_id'); $this->db->where('id_product', $id); $this->db->delete('category_product'); $data = array( 'id_product' => $id, 'id_category' => $category_id, ); $this->db->insert('category_product', $data); $data = array( 'categories' => $this->db->select('category')->from('categories')->where('id_categories', $category_id)->get()->row()->category, ); $this->db->where('id_products', $id); $this->db->update('products', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Edit Successful</p>'); redirect('admin/products/edit/' . $id); } $this->data['subview'] = 'admin/products/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to delete a product public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->product_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete image from server for ($i = 1; $i <= 5; $i++) { //check if there is an existing image on product table $this->db->select("image$i")->from('products')->where('id_products', (int) $id); $image = $this->db->get()->row_array(); //use array insted of object if ($image["image$i"] != '' || $image["image$i"] != NULL) { //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image["image$i"])) { unlink(FCPATH .'/uploads/product/'. $image["image$i"]); } if (file_exists(FCPATH . 'uploads/product/large/' . $image["image$i"])) { unlink(FCPATH .'/uploads/product/large/'. $image["image$i"]); } if (file_exists(FCPATH . 'uploads/product/small/' . $image["image$i"])) { unlink(FCPATH .'/uploads/product/small/'. $image["image$i"]); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image["image$i"])) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image["image$i"]); } } } $this->product_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Deleted Successful</p>'); redirect('admin/products'); } //callback function validation add new product public function _cek_existing_product_title($str) { $num_rows = $this->product_m->cek_existing_product_title($str, $this->product_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_product_title', 'Product name already exist !'); return FALSE; } else { return TRUE; } } private function table_data_processing($image1_filename, $image2_filename, $image3_filename, $image4_filename, $image5_filename, $image6_filename = null) { $data = array( 'title' => $this->security->xss_clean($this->input->post('product_name')), 'sku' => $this->security->xss_clean($this->input->post('sku')), 'stock' => $this->security->xss_clean($this->input->post('stock')), 'varian1' => $this->security->xss_clean($this->input->post('varian1')), 'attribute1' => $this->security->xss_clean($this->input->post('attribute1')), 'varian2' => $this->security->xss_clean($this->input->post('varian2')), 'attribute2' => $this->security->xss_clean($this->input->post('attribute2')), 'varian3' => $this->security->xss_clean($this->input->post('varian3')), 'attribute3' => $this->security->xss_clean($this->input->post('attribute3')), 'varian4' => $this->security->xss_clean($this->input->post('varian4')), 'attribute4' => $this->security->xss_clean($this->input->post('attribute4')), 'varian5' => $this->security->xss_clean($this->input->post('varian5')), 'attribute5' => $this->security->xss_clean($this->input->post('attribute5')), 'martindale' => $this->security->xss_clean($this->input->post('martindale')), 'frtest' => $this->security->xss_clean($this->input->post('frtest')), 'price' => $this->security->xss_clean($this->input->post('price')), 'alias' => url_title($this->security->xss_clean($this->input->post ('product_name'))), // 'brand_id' => (int) $this->input->post('brand_id'), 'description' => $this->security->xss_clean($this->input->post('description')), 'product_status' => $this->input->post('product_status'), 'request_sample_button' => $this->input->post('request_sample_button'), 'meta_description' => $this->security->xss_clean($this->input->post('meta_description')), ); //image upload if (isset($image1_filename)) { $data['image1'] = $image1_filename; } if (isset($image2_filename)) { $data['image2'] = $image2_filename; } if (isset($image3_filename)) { $data['image3'] = $image3_filename; } if (isset($image4_filename)) { $data['image4'] = $image4_filename; } if (isset($image5_filename)) { $data['image5'] = $image5_filename; } if (isset($image6_filename)) { $data['image6'] = $image6_filename; } return $data; } //To delete product image file from server, and from database public function delete_image($id = NULL, $image_name = NULL) { $count = $this->product_m->count_exist($id); if ($id == NULL || $image_name == NULL || $count == 0) { redirect('admin/brands'); } //get image file name for deletion $this->db->select($image_name)->from('products')->where('id_products', (int) $id); $image = $this->db->get()->row(); switch ($image_name) { case 'image1': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image1)) { unlink(FCPATH .'/uploads/product/'. $image->image1); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image1)) { unlink(FCPATH .'/uploads/product/large/'. $image->image1); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image1)) { unlink(FCPATH .'/uploads/product/small/'. $image->image1); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image1)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image1); } //Delete image field from database $data = array( 'image1' => NULL, ); break; case 'image2': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image2)) { unlink(FCPATH .'/uploads/product/'. $image->image2); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image2)) { unlink(FCPATH .'/uploads/product/large/'. $image->image2); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image2)) { unlink(FCPATH .'/uploads/product/small/'. $image->image2); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image2)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image2); } //Delete image field from database $data = array( 'image2' => NULL, ); break; case 'image3': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image3)) { unlink(FCPATH .'/uploads/product/'. $image->image3); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image3)) { unlink(FCPATH .'/uploads/product/large/'. $image->image3); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image3)) { unlink(FCPATH .'/uploads/product/small/'. $image->image3); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image3)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image3); } //Delete image field from database $data = array( 'image3' => NULL, ); break; case 'image4': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image4)) { unlink(FCPATH .'/uploads/product/'. $image->image4); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image4)) { unlink(FCPATH .'/uploads/product/large/'. $image->image4); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image4)) { unlink(FCPATH .'/uploads/product/small/'. $image->image4); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image4)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image4); } //Delete image field from database $data = array( 'image4' => NULL, ); break; case 'image5': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image5)) { unlink(FCPATH .'/uploads/product/'. $image->image5); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image5)) { unlink(FCPATH .'/uploads/product/large/'. $image->image5); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image5)) { unlink(FCPATH .'/uploads/product/small/'. $image->image5); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image5)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image5); } //Delete image field from database $data = array( 'image5' => NULL, ); break; case 'image6': //Delete the actual image file from server. FCPATH is codeigniter base path if (file_exists(FCPATH . 'uploads/product/' . $image->image6)) { unlink(FCPATH .'/uploads/product/'. $image->image6); } if (file_exists(FCPATH . 'uploads/product/large/' . $image->image6)) { unlink(FCPATH .'/uploads/product/large/'. $image->image6); } if (file_exists(FCPATH . 'uploads/product/small/' . $image->image6)) { unlink(FCPATH .'/uploads/product/small/'. $image->image6); } if (file_exists(FCPATH . 'uploads/product/thumbnail/' . $image->image6)) { unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image6); } //Delete image field from database $data = array( 'image6' => NULL, ); break; } $this->db->where('id_products', (int) $id); $this->db->update('products', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/products/edit/' . $id); } //image upload processing private function image_processing($image_file, $field_name) { if ($image_file['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = '*'; // $config['allowed_types'] = 'jpg|png|jpeg|webp'; $config['max_size'] = '500'; $this->load->library('upload', $config); $this->upload->initialize($config); if (!$this->upload->do_upload($field_name)) { $this->session->set_flashdata('error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); echo $this->upload->display_errors(); exit(); redirect('admin/products/add'); } else { $image = $this->upload->data(); $image_filename = $image['file_name']; // $this->resize_image($image['file_name']); return $image_filename; } } } private function resize_image($image) { //Get product image dimensions from configuration table $this->db->select('product_image_width, product_image_height, product_image_large_width, product_image_large_height, product_image_small_width, product_image_small_height, product_image_thumbnail_width, product_image_thumbnail_height')->from('configuration')->where('id_configuration', 1); $image_dimension = $this->db->get()->row(); //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } }