public function upload_file($field_name,$file_name,$folder,$allowed_exts,$max_size){
$path = FCPATH."uploads".$folder;
if(!is_dir($path)){ mkdir($path); @file_put_contents($path."index.html","Forbidden"); }
$config['upload_path'] = $path;
$config['allowed_types'] = $allowed_exts;
$config['max_size'] = $max_size;
$config['file_name'] = $file_name;
$config['overwrite'] = false;
$this->load->library('upload', $config);
$uploaded = $this->upload->do_upload($field_name);
$upload_data = $this->upload->data();
if($upload_data["file_type"] && $upload_data["file_ext"] && $upload_data["client_name"]){
$status = "success";
$file_size = $upload_data["file_size"];
$file_path = $upload_data["full_path"];
$max_width = 500; // max width
$max_thumb = 250; // max thumb width
$file_path = $this->resize_me($file_path,$max_width,FALSE); // resize to max width
$thumb_name = "thumb_".$upload_data["orig_name"]; // thumb name
$thumb_url = $folder.$thumb_name; // thumb url
$thumb_path = $this->resize_me($file_path,$max_thumb,FALSE,FALSE,TRUE); // resize thumb
}
}
public function delete_upload($folder,$name){
@unlink(FCPATH.upload_base.$folder."/".$name);
}
public function resize_me($path,$width,$height,$percent = 100 ,$new = FALSE){
if( ($width && $height) || ($width) || $percent){
list($mywidth, $myheight, $type, $attr) = getimagesize($path);
$config['quality'] = "100%";
$cancel = FALSE;
if($width > $mywidth){
$width = $mywidth;
}
$config['width'] = $width;
$config['maintain_ratio'] = TRUE;
$this->load->library('image_lib');
// resize
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
if($new == TRUE){
$filename = basename($path);
$config['new_image'] = $path = str_replace($filename,"thumb_".$filename,$path);
}
$this->image_lib->initialize($config);
$this->image_lib->resize();
// resize
return $path;
}
}