February 26 2010
CodeIgniter GD Uploader and auto delect big images
Tagged Under : Absolute Path, Array, CodeIgniter, Config Upload, Image Library, Images, Lib, Library Image, Load Library, Load Model, Marker, Max Height, Max Size, Max Width, Model Data, New Image, Png, Programmer, Source Image, Thumb
Hi every one please check bellow a CodeIgniter GD underloaded function. It will be help for CodeIgniter programmer
function gd_Upload(){
$config['upload_path'] = $this->config->item(’absolute_path’).’picture’;
$config['allowed_types'] = ‘jpg|GIF|PNG’;
$config['max_size'] = ‘1000′;
$config['max_width'] = ‘1600′;
$config['max_height'] = ‘1000′;
$this->load->library(’upload’, $config);
$temp = $this->upload->do_upload(’userfile’);
if ( !$temp)
{
$data = array(’message’ => $this->upload->display_errors());
print_r($data);
}
else
{
$success= array(’upload_data’ => $this->upload->data());
$fullpath=$this->upload->data(’file_name’);
$Gdconfig['image_library'] = ‘gd2′;
$Gdconfig['source_image'] = $this->config->item(’absolute_path’).’picture/’.$success['upload_data']['file_name'].”;
$Gdconfig['new_image']=$this->config->item(’absolute_path’).”picture/”.$this->session->userdata(”w_id”).$success['upload_data']['file_ext'].”";
$Gdconfig['create_thumb'] = TRUE;
$Gdconfig['maintain_ratio'] = TRUE;
$Gdconfig['width'] = 185;
$Gdconfig['height'] = 185;
$Gdconfig['thumb_marker'] =”_thumb”;
$this->image_lib->initialize($Gdconfig);
$this->load->library(’image_lib’, $Gdconfig);
$this->image_lib->resize();
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}else{
$this->load->model(’W_user_model’);
$data=$this->W_user_model->gd_Upload( $this->session->userdata(”w_id”).”_thumb”.$success['upload_data']['file_ext']);
if($data){
$unlink=unlink ($this->config->item(’absolute_path’).”picture/”.$success['upload_data']['file_name']);
if($unlink){
$this->WorkerHome();
}
}
}
}
}
}

