Im doing multiple file uploading, which is working fine.
im getting both images but the other image which is thumnail not getting their given path and also not changing in to thumb size.
I have just issues with thumbnail in "thumbnail creation start" area i hope.
check my array and let me know my mistake.
controller codes
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $image['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 150;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->upload->do_upload();
$data = $this->upload->data();
$name_array1[] = $data['file_name']; // file names for thumb
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
Replace
$config1['source_image'] = $image['full_path'];
To
$config1['source_image'] = $data['full_path'];
Also remove the following commented lines
$this->image_lib->resize();
//$this->upload->do_upload();
//$data = $this->upload->data();
After you do config for your image i.e., setting your image attributes then you should clear and initizliae the image_lib to get effect.
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
Note :
Make sure that you need it for $config or $config1
Make sure that you have the source_image path right
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 500;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->clear();
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$name_array1[] = $data['file_name']; // get file names for thumb file
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
Related
i trying to upload file but its still cant insert to database i dont know why, i've try many code but none of it working, much appreciate if you help me
here's my code :
$upload_image_dp1 = $_FILES['upload_dp1']['name'];
$upload_image_dp2 = $_FILES['upload_dp2']['name'];
$upload_image_dp3 = $_FILES['upload_dp3']['name'];
$upload_file_invoice = $_FILES['upload_invoice']['name'];
if (!empty($upload_image_dp1) && !empty($upload_image_dp2) && !empty($upload_image_dp3) && !empty($upload_file_invoice)) {
$config['upload_path'] = './assets/img/uploads/dp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10240';
$this->load->library('upload', $config);
// $config2['upload_path'] = './assets/img/uploads/invoice/';
// $config2['allowed_types'] = 'pdf';
// $config2['max_size'] = '10240';
// $this->load->library('upload', $config2);
$upload_dp1 = $this->upload->do_upload('upload_dp1');
$file1 = $this->upload->data('file_name');
$upload_dp2 = $this->upload->do_upload('upload_dp2');
$file2 = $this->upload->data('file_name');
$upload_dp3 = $this->upload->do_upload('upload_dp3');
$file3 = $this->upload->data('file_name');
$upload_invoice = $this->upload->do_upload('upload_invoice');
$file4 = $this->upload->data('file_name');
$this->db->set('upload_dp1', $file1);
$this->db->set('upload_dp2', $file2);
$this->db->set('upload_dp3', $file3);
$this->db->set('upload_invoice', $file4);
$this->db->where('id_user', $this->user['id_user']);
$this->db->where('status', "Not Complete");
$this->db->where('id_type', $id_type);
$this->db->update('passanger');
public function upload()
{
$upload_image_dp1 = $_FILES['upload_dp1']['name'];
$upload_image_dp2 = $_FILES['upload_dp2']['name'];
$upload_image_dp3 = $_FILES['upload_dp3']['name'];
$upload_file_invoice = $_FILES['upload_invoice']['name'];
$config['upload_path'] = './assets/img/uploads/dp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10240';
$this->load->library('upload', $config);
$upload_dp1 = $this->upload->do_upload('upload_dp1');
$file1 = $this->upload->data('file_name');
$upload_dp2 = $this->upload->do_upload('upload_dp2');
$file2 = $this->upload->data('file_name');
$upload_dp3 = $this->upload->do_upload('upload_dp3');
$file3 = $this->upload->data('file_name');
$upload_invoice = $this->upload->do_upload('upload_invoice');
$file4 = $this->upload->data('file_name');
$this->load->library('upload', $config);
if (!empty($upload_image_dp1) && !empty($upload_image_dp2) && !empty($upload_image_dp3) && !empty($upload_file_invoice))
{
$uploaddata = array(
'upload_dp1' => $file1,
'upload_dp2' => $file2,
'upload_dp3' => $file3,
'upload_invoice' => $file4
);
$this->User_model->update(1,$uploaddata);
$this->session->set_flashdata('success', 'Successfully Insert Your Resume We Will Contact Shortly');
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
}
===> MODEL
public function update($id,$data)
{
$this->db->where('id','1');
$this->db->update('testingupload',$data);
}
Please Use your Where condition
I have a form which contains two choose file buttons one for image and second one is for file upload but in it, my image functionality is working correctly in it but when I upload my doc file this is not working properly.Please help me
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++) {
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './upload/article_img/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
$names= implode(',', $name_array);
$this->load->database();
$db_data = array(
'article_id'=> $is_product_saved,
'image_title'=>json_encode($this->input->post('image_title')),
'file_name'=> $names,
'created_date' => date('Y-m-d H:i:s')
);
$is_saved_img = $this->site_model->save_data('article_image',$db_data);
if($_FILES["files"]["name"] != ''){
$output = '';
$config["upload_path"] = './upload/article_doc/';
$config["allowed_types"] = 'txt|pdf|doc';
//$this->load->library('upload', $config);
$this->upload->initialize($config);
for($count = 0; $count<count($_FILES["files"]["name"]); $count++)
{
$_FILES["file"]["name"] = $_FILES["files"]["name"][$count];
$_FILES["file"]["type"] = $_FILES["files"]["type"][$count];
$_FILES["file"]["tmp_name"] = $_FILES["files"]["tmp_name"][$count];
$_FILES["file"]["error"] = $_FILES["files"]["error"][$count];
$_FILES["file"]["size"] = $_FILES["files"]["size"][$count];
if($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$output[] =$data["file_name"];
}
}
$name_doc= implode(',', $output);
$db = array(
'doc_name'=> $name_doc,
'article_id'=> $is_product_saved,
'doc_title'=>json_encode($this->input->post('document_title')),
'created_date' => date('Y-m-d H:i:s')
);
$is_saved_img = $this->site_model->save_data('article_document',$db);
}
remove } from if statement its work
if($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$output[] =$data["file_name"];
}
// } remove this extra bracket because its end `for loop`
I made a function on the CodeIgniter framework so users can upload pictures of products to a product page. The thing is I want pictures to be resized to the width and height I want it to be. Since I added the image lib resize function in my upload function nothing is working anymore.
This is my upload function:
public function upload() {
$this->load->library('upload');
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('product_form', $error);
} else {
$file_data = $this->upload->data();
$this->load->library('image_lib');
foreach ($results as $row) {
$config['image_library'] = 'gd2';
$config['source_image'] = './upload/' . $file_data["file_name"];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
$this->db->insert('products', array(
'product_foto' => $file_data['file_name'],
'product_naam' => $this->input->post('product_naam'),
'product_beschrijving' => $this->input->post('product_beschrijving'),
'product_categorie' => $this->input->post('product_categorie'),
'ophaal_plaats' => $this->input->post('ophaal_plaats'),
'date_created' => date('Y-m-d'),
'date_updated' => date('Y-m-d')
));
$data['img'] = base_url() . '/upload/' . $file_data['file_name'];
header('location:https://kadokado-ferran10.c9users.io/Product/');
}
What am I doing wrong?
It works for me :
if(!empty($_FILES['image_field']['name']))
{
$config['upload_path'] = './image_folder';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '262144';
$config['overwrite'] = FALSE;
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image_field'))
{
echo "Not Upload";
echo $this->upload->display_errors();
// $this->session->set_flashdata('error','<div class="alert alert-warning">Something went wrong...try again...</div>');
//redirect('Controller/function_name');
}
else
{
$image_data = $this->upload->data();
$config1['image_library'] = 'gd2';
$config1['source_image'] = './image_folder/'.$image_data['file_name'];
$config1['maintain_ratio'] = TRUE;
$config1['quality'] = '50%';
$config1['width'] = 50;
$config1['height'] = 50;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
echo $image_data['file_name'];
exit;
// save to database
}
}
Hello i need help below is my code
It doesn't update any think except the avatar always display error You did not select a file to upload.
don't know how to solve it please help
if($this->input->post()){
$this->form_validation->set_rules('avatar','avatar','callback_multiple_image_upload|trim');
$this->form_validation->set_rules('overview','overview','trim');
$this->form_validation->set_rules('history','history','trim');
$this->form_validation->set_rules('education','education','trim');
$this->form_validation->set_rules('joining','joining','trim');
$this->form_validation->set_rules('hobbies','hobbies','trim');
$this->form_validation->set_rules('experience','experience','trim');
$this->form_validation->set_rules('skills','skills','trim');
/* if($this->input->post('avatar')){
$this->form_validation->set_rules('avatar','avatar','callback_multiple_image_upload|trim');
}else{} */
if($this->form_validation->run())
{
// check if avatar is uploaded
$images = ($this->session->userdata('uploaded_images'))?$this->session->userdata('uploaded_images'):array();
if($this->session->userdata('uploaded_avatar')){
$user['avatar'] = $this->session->userdata('uploaded_avatar');
$this->session->unset_userdata('uploaded_avatar');
}
$data = array(
'avatar' => ($images)?$images[0]['file_name']:'',
'thumb' => ($images)?$images[0]['thumb']:'',
'overview' =>$this->input->post('overview'),
'history' =>$this->input->post('history'),
'education' =>$this->input->post('education'),
'joining' =>$this->input->post('joining'),
'hobbies' =>$this->input->post('hobbies'),
'experience' =>$this->input->post('experience'),
'skills' =>$this->input->post('skills'),
);
$abc = $this->user_model->update($user_id,$data,'user_id');
$this->session->set_flashdata('success','User updated successfully');
redirect('admin/staff/edit/'.$user_id);
}
}
public function multiple_image_upload()
{
$config = array();
$config['upload_path'] = './uploads/user_avatars/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$config['max_width'] = 10240;
$config['max_height'] = 7680;
//$images = array();
if(isset($_FILES['avatar']) && ($count = count($_FILES['avatar']['name'])) > 0)
{
$files = $_FILES;
$images = array();
/* check if folder with year exists*/
$current_year = date('Y');
$path = './uploads/user_avatars/'.$current_year;
if(is_dir($path)){
/* do nothing */
}else{
/* create directory */
#mkdir( $path , 0755, true );
}
$images = array();
for($i = 0; $i < $count; $i++)
{
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '100000';
$config['max_width'] = '102400';
$config['max_height'] = '76800';
$this->load->library('upload', $config);
if ($this->upload->do_upload('avatar'))
{
$data = $this->upload->data();
/* create thumbnail */
$this->load->helper('image_thumb_helper');
generate_image_thumb($data['full_path'],$path,$data['file_name']);
/* add to database */
$images[$i]['file_name'] = $current_year.'/'.$data['file_name'];
$images[$i]['thumb'] = $current_year.'/thumb_'.$data['file_name'];
}else{
$this->form_validation->set_message('multiple_image_upload',$this->upload->display_errors());
return false;
}
}
$this->session->set_userdata('uploaded_images',$images);
return true;
}
else{
return true;
}
}
please provide me solution m not able to remove this error :(
I thing you are using multifile upload. please try bellow one for "for loop"
for($i = 0; $i < $count; $i++)
{
$_FILES['avatar_solo']['name'] = $_FILES['avatar']['name'][$i];
$_FILES['avatar_solo']['type'] = $_FILES['avatar']['type'][$i];
$_FILES['avatar_solo']['tmp_name'] = $_FILES['avatar']['tmp_name'][$i];
$_FILES['avatar_solo']['error'] = $_FILES['avatar']['error'][$i];
$_FILES['avatar_solo']['size'] = $_FILES['avatar']['size'][$i];
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '100000';
$config['max_width'] = '102400';
$config['max_height'] = '76800';
$this->load->library('upload', $config);
if ($this->upload->do_upload('avatar_solo'))
{
$data = $this->upload->data();
/* create thumbnail */
$this->load->helper('image_thumb_helper');
generate_image_thumb($data['full_path'],$path,$data['file_name']);
/* add to database */
$images[$i]['file_name'] = $current_year.'/'.$data['file_name'];
$images[$i]['thumb'] = $current_year.'/thumb_'.$data['file_name'];
}else{
$this->form_validation->set_message('multiple_image_upload',$this->upload->display_errors());
return false;
}
}
Controller
public function insertDepartmentImage()
{
$this->load->model('Gallery_Model/Gallery_Model');
$config['upload_path'] = './uploads/galleryImg';
$config['allowed_types'] = 'png|jpg|gif|jpeg';
$config['max_size'] = '10000000';
$config['file_name']='smallImage';
$config['file_name1']='bigImage';
$config['overwrite']=false;
$this->load->library('upload', $config);
if (!is_dir('uploads'))
{
mkdir('./uploads', 0777, true);
}
$dir_exist = true;
if (!is_dir('uploads/' . $album))
{
mkdir('./uploads/' . $album, 0777, true);
$dir_exist = false; // dir not exist
}
else{ }
if (!$this->upload->do_upload('filename'))
{
$this->load->model('Gallery_Model/Gallery_Model');
$upload_error = array('error' => $this->upload->display_errors());
$this->load->view('/admin/Gallery/vwGallery',$upload_error);
}
else
{
$upload_data = $this->upload->data();
$data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
$this->load->model('Gallery_Model/Gallery_Model');
$file_name = $upload_data['file_name'];
$file_name1 = $upload_data['file_name1'];
$deptId = $this->input->post('deptId');
$deptDetails = $this->input->post('deptDetails');
$deptDetails1 = $this->input->post('deptDetails1');
$this->Gallery_Model->insertDepartmentImage($deptId,$file_name,$file_name1,$deptDetails,$deptDetails1);
}
}
It work fine but uploading only one filename into database. I have to upload one more image into database. But its not working.For Uploading Another image what to do for this.
In my view I have given two input field <input id="file-0" name="filename" class="file" type="file" multiple="true" />
<input id="file-0" name="filename1" class="file" type="file" multiple="true" />
Thank you guys. But I will just changing code into Controller and It's worked for me.
public function insertDepartmentImage()
{
$m = $_FILES['filename']['name'];
$n = $_FILES['filename1']['name'];
if ($m !== "")
{
$config['upload_path'] = './uploads/galleryImg';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] = '100000'; // 0 = no file size limit
$config['file_name']='smallImage';
$config['overwrite'] = false;
$this->load->library('upload', $config);
$this->upload->do_upload('filename');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
if ($n !== "")
{
$config['file_name']='bigImage';
$config['upload_path'] = './uploads/galleryImg';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] = '100000'; // 0 = no file size limit
$config['overwrite'] = false;
$this->load->library('upload', $config);
$this->upload->do_upload('filename1');
$upload_data = $this->upload->data();
$file_name1 = $upload_data['file_name'];
}
$deptId = $this->input->post('deptId');
$deptDetails = $this->input->post('deptDetails');
$deptDetails1 = $this->input->post('deptDetails1');
$this->Gallery_Model->insertDepartmentImage($deptId,$file_name,$file_name1,$deptDetails,$deptDetails1);
}/* closed insertDepartmentImage*/
View
<input id="file-0" name="filename" class="file" type="file" multiple="true" />
<input id="file-0" name="filename1" class="file" type="file" multiple="true" />
By default codeIgniter doesn't support multi-file upload. So you can use this library CodeIgniter Multiple Upload Library
https://github.com/anuragrath/CodeIgniter-Multiple-File-Upload
Thank you guys... I solve my problem now...
Here are my code, hope it can help
public function dashboard_templatedefault(){
$upload1 = $_FILES['upload1']['name'];
$upload2 = $_FILES['upload2']['name'];
$upload3 = $_FILES['upload3']['name'];
$upload4 = $_FILES['upload4']['name'];
$upload5 = $_FILES['upload5']['name'];
$upload6 = $_FILES['upload6']['name'];
$upload7 = $_FILES['upload7']['name'];
$upload8 = $_FILES['upload8']['name'];
if($upload1 !== ""){
$config['upload_path'] = './upload/';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] = '0'; // 0 = no file size limit
$config['file_name']='upload1';
$config['overwrite'] = false;
$this->load->library('upload', $config);
$this->upload->do_upload('upload1');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
if($upload2 !== ""){
$config['file_name']='upload2';
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] = '0'; // 0 = no file size limit
$config['overwrite'] = false;
$this->load->library('upload', $config);
$this->upload->do_upload('upload2');
$upload_data = $this->upload->data();
$file_name1 = $upload_data['file_name'];
}
if($upload3 !== ""){
$config['file_name']='upload3';
$config['upload_path'] ='./upload/';
$config['allowed_types'] ='jpg|png|jpeg|gif';
$config['max_size'] = '0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload3');
$upload_data = $this->upload->data();
$file_name2 = $upload_data['file_name'];
}
if($upload4 !== ""){
$config['file_name'] = 'upload4';
$config['upload_path'] ='./upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] ='0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload4');
$upload_data = $this->upload->data();
$file_name3 = $upload_data['file_name'];
}
if($upload5 !== ""){
$config['file_name'] = 'upload5';
$config['upload_path'] ='./upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] ='0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload5');
$upload_data = $this->upload->data();
$file_name4 = $upload_data['file_name'];
}
if($upload6 !== ""){
$config['file_name'] = 'upload6';
$config['upload_path'] ='./upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] ='0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload6');
$upload_data = $this->upload->data();
$file_name5 = $upload_data['file_name'];
}
if($upload7 !== ""){
$config['file_name'] = 'upload7';
$config['upload_path'] ='./upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] ='0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload7');
$upload_data = $this->upload->data();
$file_name6 = $upload_data['file_name'];
}
if($upload8 !== ""){
$config['file_name'] = 'upload8';
$config['upload_path'] ='./upload/';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] ='0';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('upload8');
$upload_data = $this->upload->data();
$file_name7 = $upload_data['file_name'];
}
$this->form_validation->set_rules('name','','xss_clean');
$this->form_validation->set_rules('occasion','','xss_clean');
$this->form_validation->set_rules('party_date','','xss_clean');
$this->form_validation->set_rules('location','','xss_clean');
$this->form_validation->set_rules('upload1','','xss_clean');
$this->form_validation->set_rules('upload2','','xss_clean');
$this->form_validation->set_rules('upload3','','xss_clean');
$this->form_validation->set_rules('upload4','','xss_clean');
$this->form_validation->set_rules('upload5','','xss_clean');
$this->form_validation->set_rules('upload6','','xss_clean');
$this->form_validation->set_rules('upload7','','xss_clean');
$this->form_validation->set_rules('upload8','','xss_clean');
$this->form_validation->run();
$template_name = $this->input->post('template_name');
$name = $this->input->post('name');
$occasion = $this->input->post('occasion');
$party_date = $this->input->post('party_date');
$location = $this->input->post('location');
$created = date('h:m:s a m/d/y');
$profile_id = $this->input->post('profile_id');
$this->admin_model->dashboard_templatedefault($template_name,$name,$occasion,$party_date,$location,$created,$profile_id,$upload1,$upload2,$upload3,$upload4,$upload5,$upload6,$upload7,$upload8);
}
You code is seems too long try this one
public function insertDepartmentImage()
{
$upload1 = $_FILES['upload1']['name'];
$upload2 = $_FILES['upload2']['name'];
$config = array(
'upload_path' => './uploads/galleryImg/',
'log_threshold' => 1,
'allowed_types' => 'jpg|png|jpeg|gif',
'max_size' => '0',
'overwrite' => false
);
for($i = 1; $i<=2; $i++){
if(!empty('$upload'.$i)){
$config['file_name']='upload'.$i;
$this->load->library('upload', $config);
$this->upload->do_upload('upload'.$i);
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
}
$deptId = $this->input->post('deptId');
$deptDetails = $this->input->post('deptDetails');
$deptDetails1 = $this->input->post('deptDetails1');
$this->Gallery_Model->insertDepartmentImage($deptId,$file_name,$file_name1,$deptDetails,$deptDetails1);
}