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
1views
2---------
3
4<?php echo validation_errors();?>
5<?php echo form_open_multipart('pages/multiple_files');?>
6<p><input type="file" multiple="multiple" name="image_name[]" class="form-control" /></p>
7
8<input type="submit" class="btn btn-success btn-block"/>
9</form>
10
11Controller
12----------
13
14public function multiple_files(){
15 $this->load->library('upload');
16 $image = array();
17 $ImageCount = count($_FILES['image_name']['name']);
18 for($i = 0; $i < $ImageCount; $i++){
19 $_FILES['file']['name'] = $_FILES['image_name']['name'][$i];
20 $_FILES['file']['type'] = $_FILES['image_name']['type'][$i];
21 $_FILES['file']['tmp_name'] = $_FILES['image_name']['tmp_name'][$i];
22 $_FILES['file']['error'] = $_FILES['image_name']['error'][$i];
23 $_FILES['file']['size'] = $_FILES['image_name']['size'][$i];
24
25 // File upload configuration
26 $uploadPath = './assets/images/profiles/';
27 $config['upload_path'] = $uploadPath;
28 $config['allowed_types'] = 'jpg|jpeg|png|gif';
29
30 // Load and initialize upload library
31 $this->load->library('upload', $config);
32 $this->upload->initialize($config);
33
34 // Upload file to server
35 if($this->upload->do_upload('file')){
36 // Uploaded file data
37 $imageData = $this->upload->data();
38 $uploadImgData[$i]['image_name'] = $imageData['file_name'];
39
40 }
41 }
42 if(!empty($uploadImgData)){
43 // Insert files data into the database
44 $this->pages_model->multiple_images($uploadImgData);
45 }
46 }
47
48Model
49---------
50 public function multiple_images($image = array()){
51
52 return $this->db->insert_batch('profile_images',$image);
53 }
54
55