<div class="form-group"> <div class="col-sm-9"> <div class="fileinput fileinput-new" data-provides="fileinput"> <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"> <?php //if there is an image if (get_footer_link_info_by_id($id, 'image')) { ?> <img src="<?= base_url() . 'uploads/footer_link_logos/' . get_thumbnail(get_footer_link_info_by_id($id, 'image')) ?>"> <?php } ?> </div> <div> <?php $data = array ( 'name' => 'userfile', 'id' => 'userfile', 'value' => set_value('userfile'), 'maxlength' => '', 'size' => '',
function do_upload_update($folder_name){ $config['upload_path']='./uploads/'.$folder_name;//remember to create a folder called uploads in root folder $config['allowed_types']='gif|png|jpg|jpeg'; //to prevent overly gigantic photos $config['max_size']='10000';//always in kilobytes $config['max_height']='130240';//aways in pixels $config['max_width']='10680';//aways in pixels $config['file_name'] = IMAGES_NAME; //load the library and passin configs $this->load->library('upload',$config); //to perform the upload $upload= $this->upload->do_upload(); //if upload successfull if ($upload) { //fetch image data $image_data=$this->upload->data(); //resize the image //configs to resize image $config['image_library']='gd2'; $config['source_image']=$image_data['full_path']; $config['create_thumb']=TRUE; $config['maintain_ratio']=TRUE; $config['width']=150;//in px always $config['height']=150; $config['new_image']='./uploads/'.$folder_name; //load image library and attach configs to it $this->load->library('image_lib',$config); //tell the library ti resize $this->image_lib->resize(); //do the photo insert $photo_data['imageurl']=$image_data['file_name']; $upload_data=array ( 'imageurl' =>$image_data['file_name'] ); //delete previouse image if(get_footer_link_info_by_id($this->input->post('id'),'image'))//if there is an image { unlink('uploads/footer_link_logos/'.get_thumbnail(get_footer_link_info_by_id($this->input->post('id'),'image'))); unlink('uploads/footer_link_logos/'.get_footer_link_info_by_id($this->input->post('id'),'image')); } $upload_file=$this->update($this->input->post('id'),$upload_data); if($upload_file) { return TRUE; } else { return false; } } else { return $this->upload->display_errors(); } }