1if($this->input->post('Submit')){
2
3//-----------Image File Section Start Here -----------//
4
5 $config['upload_path'] = './uploads/'; // Directory
6$config['allowed_types'] = 'jpg|jpeg|bmp|png'; //type of images allowed
7$config['max_size'] = '30720'; //Max Size
8$config['encrypt_name'] = TRUE; // For unique image name at a time
9
10$this->load->library('upload', $config); //File Uploading library
11$this->upload->do_upload('userfile'); // input name which have to upload
12$video_upload=$this->upload->data(); //variable which store the path
13
14//--------------End of Image File Section------------------------//
15
16
17
18//---------Thumbnail Image Upload Section Start Here -----------//
19
20$config2['upload_path'] = './thumb/'; // Directory
21$config2['allowed_types'] = 'jpg|jpeg|bmp|png'; //type of images allowed
22$config2['max_size'] = '30720'; //Max Size
23$config2['encrypt_name'] = TRUE; // For unique image name at a time
24
25
26$this->upload->initialize($config2); //we can not use upload library again and again it will not initialize again and again so thats why i have used initialize
27$this->upload->do_upload('txt_thumb'); // File Name
28$thumbnail_upload=$this->upload->data(); // store the name of the file
29
30//--------End of Thumbnail Upload Section-----------//
31
32
33
34 $date=date("d-m-Y"); // Store current date in variable
35
36 // Here the database query to insert
37
38 $data = array(
39 'parent_id'=> $this->input->post('txt_parent'),
40 'cat_id' => $this->input->post('txt_category'),
41 'title'=> $this->input->post('txt_title'),
42 'status' => $this->input->post('txt_status'),
43 'featured' => $thumbnail_upload['file_name'],
44 'image' => $video_upload['file_name'],
45 'time'=>$date
46 );
47
48 $sql_ins= $this->Insimage->insertimage($data);
49 if($sql_ins)
50 {
51 $data['Success'] = "Image has been succesfully inserted!!";
52 }
1 private function upload_files($path, $title, $files)
2 {
3 $config = array(
4 'upload_path' => $path,
5 'allowed_types' => 'jpg|gif|png',
6 'overwrite' => 1,
7 );
8
9 $this->load->library('upload', $config);
10
11 $images = array();
12
13 foreach ($files['name'] as $key => $image) {
14 $_FILES['images[]']['name']= $files['name'][$key];
15 $_FILES['images[]']['type']= $files['type'][$key];
16 $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
17 $_FILES['images[]']['error']= $files['error'][$key];
18 $_FILES['images[]']['size']= $files['size'][$key];
19
20 $fileName = $title .'_'. $image;
21
22 $images[] = $fileName;
23
24 $config['file_name'] = $fileName;
25
26 $this->upload->initialize($config);
27
28 if ($this->upload->do_upload('images[]')) {
29 $this->upload->data();
30 } else {
31 return false;
32 }
33 }
34
35 return $images;
36 }
37