[eluser]Adnan1984[/eluser]
hello, Here is my program code in controller:
Code:
public function create_user(){
$this->load->library('form_validation');
$this->form_validation->set_rules('userfile','','trim|callback_upload1|xss_clean');
$this->form_validation->set_rules('ref','Reference','trim|required|alpha_numeric|xss_clean');
if($this->form_validation->run()== FALSE) {
$this->load->view('create_user_view');
}else{
[b]$this->upload1();[/b]
$this->load->model('admin_model');
$this->admin_model->user_insert();
$this->load->view('create_user_view');
}
}
}
public function upload1(){
/*----- Upload -----*/
if ( isset($_FILES['userfile']['name']) AND strlen($_FILES['userfile']['name']) > 3 ){
$this->gallery_path = realpath(APPPATH.'../uploads');
$this->gallery_path_url=base_url().'uploads/';
$config['upload_path'] = $this->gallery_path;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2000';
$config['file_name'] = $this->input->post('ref');
$this->load->library('upload',$config);
if (! $this->upload->do_upload()){
//echo $this->upload->display_errors();
$this->form_validation->set_message('upload1','Something Wrong Image Type');
return FALSE;
}
$image_data = $this->upload->data();
/*----- Image Config -----*/
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = $this->gallery_path.'/thumbs';
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 100;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}
I created form, in which i'm using image upload function. But when i post the form without filling the required field, Validation error comes but image uploaded in the folder. that shouldn't be happened. Any Idea?
Thanks