1if($this->input->post())
2{
3 $file_element_name = 'image'; //this is the name of your input file. for example "image"
4 if ($_FILES['image']['name']!= "")
5 {
6 $config['upload_path'] = './uploads/';
7 $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip';
8 $config['max_size'] = '8192';
9 $config['remove_spaces']=TRUE; //it will remove all spaces
10 $config['encrypt_name']=TRUE; //it wil encrypte the original file name
11 $this->load->library('upload', $config);
12
13 if (!$this->upload->do_upload($file_element_name))
14 {
15 $error = array('error' => $this->upload->display_errors());
16 $this->session->set_flashdata('error',$error['error']);
17 redirect('controller_name/function_name','refresh');
18 }
19 else
20 {
21 $data = $this->upload->data();
22 return $data['file_name'];
23 }
24 $this->session->set_flashdata('msg','success message');
25 redirect('controller_name/function_name','refresh');
26 }
27 else
28 {
29 //if no file uploaded the do stuff here
30 }
31}