php - Codeigniter - How to upload original image with thumbnail image? -
i have code file upload in codeigniter:
if(!empty($_files['userfile'])){ $name_array = array(); $count = count($_files['userfile']['size']); foreach($_files $key => $value) ($s=0; $s<=$count-1; $s++){ $_files['userfile']['name'] = $value['name'][$s]; $_files['userfile']['type'] = $value['type'][$s]; $_files['userfile']['tmp_name'] = $value['tmp_name'][$s]; $_files['userfile']['error'] = $value['error'][$s]; $_files['userfile']['size'] = $value['size'][$s]; $config['upload_path'] = './public/images/campaign-images/'; $config['allowed_types'] = 'gif|jpg|jpeg|png|gif|jpg|jpeg|png'; $config['max_size'] = '10000'; //$config['max_width'] = '1024'; //$config['max_height'] = '768'; $ci->load->library('upload', $config); $ci->upload->do_upload(); $data = $ci->upload->data(); $name_array[] = $data['file_name']; } return $name_array; }
this code working perfect single original image upload how upload image thumbnail image(350 x 250) resize in different folder.
any idea how codeigniter library?
thanks
first store original image , afterwards thumbnail image upload need include gd2 library generate thumbnail image
if(!empty($_files['userfile'])){ $name_array = array(); $count = count($_files['userfile']['size']); foreach($_files $key => $value) ($s=0; $s<=$count-1; $s++) { //original image upload - start $_files['userfile']['name'] = $value['name'][$s]; $_files['userfile']['type'] = $value['type'][$s]; $_files['userfile']['tmp_name'] = $value['tmp_name'][$s]; $_files['userfile']['error'] = $value['error'][$s]; $_files['userfile']['size'] = $value['size'][$s]; $config['upload_path'] = './public/images/campaign-images/'; $config['allowed_types'] = 'gif|jpg|jpeg|png|gif|jpg|jpeg|png'; $config['max_size'] = '10000'; //$config['max_width'] = '1024'; //$config['max_height'] = '768'; $ci->load->library('upload', $config); $ci->upload->do_upload(); $data = $ci->upload->data(); //original image upload - end //thumbnail image upload - start $config['image_library'] = 'gd2'; $config['source_image'] = './public/images/campaign-images/'. $value['name'][$s]; $config['new_image'] = './public/images/campaign-images/thumbs/'.$value['name'][$s]; $config['width'] = 350; $config['height'] = 250; //load resize library $this->load->library('image_lib', $config); $this->image_lib->resize(); //thumbnail image upload - end $name_array[] = $data['file_name']; } return $name_array; }
Comments
Post a Comment