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
Related
I'm stuck on a problem with updating image. I did upload the multiple image and inserted in database but I can not override these images in database or my upload folder how can I override the images in my upload folder and my database.
I do multiple image upload in CodeIgniter; the same code is used to update the the multiple image but in the update time:
public function edit_package($package_id){
$pname = $this->input->post('pname');
$pdur = $this->input->post('pdur');
$pdelprice = $this->input->post('pdelprice');
$price = $this->input->post('price');
$pcat = $this->input->post('pcat');
$pc = $this->input->post('pc');
$ploc = $this->input->post('ploc');
$pcat = $this->input->post('pcat');
$accom1 = $this->input->post('accom1');
$accom2 = $this->input->post('accom2');
$accom3 = $this->input->post('accom3');
$accom4 = $this->input->post('accom4');
$accom5 = $this->input->post('accom5');
$accom6 = $this->input->post('accom6');
// Displaying Errors in view
$this->form_validation->set_error_delimiters('<span style="color:red;">', '</span>');
$this->form_validation->set_rules('pname', 'Package Name', 'required');
$this->form_validation->set_rules('pdur', 'Package Duration', 'required');
$this->form_validation->set_rules('price', 'Package Price', 'required');
$this->form_validation->set_rules('pdelprice', 'Package offer Price', 'required');
$this->form_validation->set_rules('pc', 'Places Covered', 'required');
$this->form_validation->set_rules('pcat', 'Package Category', 'required');
$this->form_validation->set_rules('ploc', 'Package Location', 'required');
if ($this->form_validation->run() == False)
{
$data['editPackage'] = $this->Packages_model->editPackageVlaues($package_id);
$data['editPackage'] = $this->Packages_model->editPackageVlaues($package_id);
$data['editLocation'] = $this->Packages_model->edit_location();
$data['editPackCate'] = $this->Packages_model->getCategoryName();
$data['pkg_cat'] = $this->Packages_model->get_pkg_cat();
$data['pkg_loc'] = $this->Api_location_model->get_locations();
$this->load->view('Admin_panel/admin_assets');
$this->load->view('Admin_panel/panel');
$this->load->view('Admin_panel/Packages/edit_package',$data);
$this->load->view('Admin_panel/footer');
}
extract($_POST);
if(isset($update_package))
{
$filesCount = count($_FILES['pkg_img']['name']);
for($i = 0; $i < $filesCount; $i++)
{
$_FILES['userFile']['name'] = $_FILES['pkg_img']['name'][$i];
$_FILES['userFile']['type'] = $_FILES['pkg_img']['type'][$i];
$_FILES['userFile']['tmp_name'] = $_FILES['pkg_img']['tmp_name'][$i];
$_FILES['userFile']['error'] = $_FILES['pkg_img']['error'][$i];
$_FILES['userFile']['size'] = $_FILES['pkg_img']['size'][$i];
$config['upload_path'] = 'resources/neeraj/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|GIF|JPEG|PNG|JPG';
$config['overwrite'] = TRUE;
$config['max_size'] = 2048000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->upload->initialize($config);
if($this->upload->do_upload())
{
$fileData[] = $this->upload->data();
$fileName = $fileData['file_name'];
$images[] = $fileName;
$error = array('error' => $this->upload->display_errors());
$fileName = $this->upload->data('file_name');
if($this->Packages_model->update_packages($package_id,$pname,$pdur,$pdelprice,$price,$pcat,$ploc,$pc,$accom1,$accom2,$accom3,$accom4,$accom5,$accom6,$fileName))
{
$this->session->set_flashdata('package_update','Package Updated successfully');
redirect('Packages_ctrl/display_packages');
}
else
{
//upload the new image
$upload_data = $this->upload->data();
$fileName = $upload_data['file_name'];
if($_POST){
$data = array('pkg_img'=>$fileName);
//update
$this->Packages_model->update_packages($data);
}
echo "<script> alert('Please Select the Hotel Image');
window.location.href='add_packages';
</script>";
}
}
}
}
}
You should supply the overwrite config parameter
$config['upload_path'] = './uploads/';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);
See the Documentation for upload preferences
I think you want to upload the multiple files using CodeIgniter. If I'm right then you have to follow this answer then definitely you got the solutions.
In View page:
<form action='index.php/upload/do_upload' enctype="multipart/form-data" method="post">
<input type="file" name="userfile[]" multiple='multiple' />
<input type="submit" value="upload" />
</form>
In Controller.
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = true;
$this->load->library('upload', $config);
$number_of_files_uploaded = count($_FILES['userfile']['name']);
for ($i = 0; $i < $number_of_files_uploaded; $i++) {
$_FILES['upl_files']['name'] = $_FILES['userfile']['name'][$i];
$_FILES['upl_files']['type'] = $_FILES['userfile']['type'][$i];
$_FILES['upl_files']['tmp_name'] = $_FILES['userfile']['tmp_name'][$i];
$_FILES['upl_files']['error'] = $_FILES['userfile']['error'][$i];
$_FILES['upl_files']['size'] = $_FILES['userfile']['size'][$i];
if ( ! $this->upload->do_upload('upl_files'))
{
$error = array('error' => $this->upload->display_errors());
var_dump($error);
$this->load->view('v_upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
var_dump( $data);
}
}
}
Please care about the name , it's important part here.
I want to insert image(path only) to database.I have written this code but here every time the default.png(path only) is inserted.I want to insert other images also.
$maxId = $this->user_master_m->get_max_product_id();
$new_file = "defualt.png";
if ($_FILES["image"]['name'] != "") {
$file_name = $_FILES["image"]['name'];
$file_name_rename = 'P-' . $maxId->id;
$explode = explode('.', $file_name);
if (count($explode) >= 2) {
$new_file = $file_name_rename . '.' . $explode[1];
$config['upload_path'] = "./uploads/images";
$config['allowed_types'] = "gif|jpg|png";
$config['file_name'] = $new_file;
$config['max_size'] = '1024';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$array['product_image'] = $new_file;
$this->load->library('upload', $config);
if (!$this->upload->do_upload("image")) {
$this->data["image"] = $this->upload->display_errors();
$this->data["subview"] = "admin_view/product_form_view";
$this->load->view('_layout_main', $this->data);
} else {
$data = array("upload_data" => $this->upload->data());
$this->user_master_m->add_product_m($array);
}
} else {
$this->data["image"] = "Invalid file";
$this->data["subview"] = "admin_view/product_form_view";
$this->load->view('_layout_main', $this->data);
}
} else {
$array["product_image"] = $new_file;
$this->user_master_m->add_product_m($array);
}
Try to print $_FILES by
print_r($_FILES);
to check whether you are getting the image properly or not.
I am trying to upload an image.
Here is the code
<?php
$PerpetualCalendar = $this->input->post();
if($files['imgQuarter1']['name'][$key]!="")
{
$_FILES['imgQuarter1']['name']= $files['imgQuarter1']['name'][$key];
$_FILES['imgQuarter1']['type']= $files['imgQuarter1']['type'][$key];
$_FILES['imgQuarter1']['tmp_name']= $files['imgQuarter1']['tmp_name'][$key];
$_FILES['imgQuarter1']['error']= $files['imgQuarter1']['error'][$key];
$_FILES['imgQuarter1']['size']= $files['imgQuarter1']['size'][$key];
if(isset($PerpetualCalendar['id1'][$key]))
{
$img_id=$PerpetualCalendar['id1'][$key];
}
else
{
$img_id=$GetLastID;
}
$fileName = $img_id.'_NAME_'. $files['imgQuarter1']['name'][$key];
$config['file_name'] = $fileName;
$this->upload->initialize($config);
if($this->upload->do_upload('imgQuarter1'))
{
if(isset($PerpetualCalendar['NAMEpath_idQ1'][$key])){
$ImgUpdate[$imgkey]['tbl_name']='perpetual_calendar';
$ImgUpdate[$imgkey]['field_name']='event_name';
$ImgUpdate[$imgkey]['user_FK']=$user_id;
$ImgUpdate[$imgkey]['path']=$uploadpath.'/'.$fileName;
$ImgUpdate[$imgkey]['entry_id']=$img_id;
$ImgUpdate[$imgkey]['path_id']=$PerpetualCalendar['NAMEpath_idQ1'][$key]; //for update purpose
}else{
$ImgInsert[$imgkey]['tbl_name']='perpetual_calendar';
$ImgInsert[$imgkey]['field_name']='event_name';
$ImgInsert[$imgkey]['user_FK']=$user_id;
$ImgInsert[$imgkey]['path']=$uploadpath.'/'.$fileName;
$ImgInsert[$imgkey]['entry_id']=$img_id;
}
$imgkey++;
}
else
{
$this->data['error'] = $this->session->set_flashdata(array('error' => $this->upload->display_errors()));
}
}
?>
here is the View
echo form_upload(array('name'=>'imgQuarter1['.$key.']','class'=>'default'),'');
echo form_input(array('name' => 'id1['.$key.']', 'type'=>'hidden','value'=>$ValuePerpetualCalendar['cal_id']));
in above code,i can get $PerpetualCalendar['id1'][$key] this Id,but
image can not upload in the folder and can't save in Database Aswell !
Any Help?
public function upload_multiple_image($user_id){
$image = $_FILES['image']['name'];
$files = $_FILES['image'];
$image_title = $this->input->post('image_title');
$image_link = $this->input->post('image_link');
foreach($image as $key=>$data){
if($files['name'][$key]!=""){
$add_data['user_id'] = $user_id;
$add_data['title'] = $image_title[$key];
$add_data['description'] = $image_link[$key];
$add_data['status'] = 1;
$this->db->insert('user_images',$add_data);
$last_inserted_id = $this->db->insert_id();
$_FILES['image']['name'] = $files['name'][$key];
$_FILES['image']['type'] = $files['type'][$key];
$_FILES['image']['tmp_name'] = $files['tmp_name'][$key];
$_FILES['image']['error'] = $files['error'][$key];
$_FILES['image']['size'] = $files['size'][$key];
$config['upload_path'] = './user_images/original/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['overwrite'] = TRUE;
$config['file_name'] = 'place_image_'.$last_inserted_id;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('image')){
$file_details = $this->upload->data();
$update_data = array('image'=>$file_details['file_name']);
$this->db->update('user_images',$update_data,array('id'=>$last_inserted_id));
}
}
}
}
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);
}
I need some help. I want to upload two different files in two different directory by using codeigniter. I wrote the following code in my controller. but it will upload only the first image.
public function save_product() {
$data = array();
$error = array();
$config1['upload_path'] = './manager/images/products/';
$config1['allowed_types'] = 'gif|jpeg|png|jpg';
$config1['max_size'] = '3000000';
$config1['max_width'] = '1024';
$config1['max_height'] = '768';
$this->load->library('upload', $config1);
$config2['upload_path'] = './manager/images/products/large/';
$config2['allowed_types'] = 'gif|jpeg|png|jpg';
$config2['max_size'] = '3000000';
$config2['max_width'] = '1024';
$config2['max_height'] = '768';
$this->load->library('upload', $config2);
if ((!$this->upload->do_upload('product_small_image')) && (!$this->upload->do_upload('product_large_image'))){
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($error);
exit();
}
else {
$fdata = $this->upload->data();
$data['product_small_image'] = 'manager/images/products/' . $fdata['file_name'];
$data['product_large_image'] = 'manager/images/products/large/' . $fdata['file_name'];
$data['product_id'] = $this->input->post('product_id', TRUE);
$data['product_name'] = $this->input->post('product_name', TRUE);
$data['category'] = $this->input->post('category', TRUE);
$result = $this->super_admin_model->save_product_detail($data);
$sdata = array();
$sdata['message'] = "Well done!</strong> You successfully add the Product Details.";
$this->session->set_userdata($sdata);
redirect('super_admin/add_product', 'refresh');
}
}
First, loading the library again with $config2 won't work because the library is already loaded once and $config1 will stay loaded. To load a new config use $this->upload->initialize($config2);
Second, loading $config2 will overwrite the previous config. You should re-arrange your code. Otherwise both uploads will only use the latest config ($config2). Example:
Load library with $config1
Process do_upload('product_small_image') and collect result
Load $confg2 using initialize()
Process do_upload('product_large_image') and collect result
Process results (save to db if success or display error if one of the uploads failed)
Here is the total code what i wrote to upload multiple image in different directory successfully. and thanks to #Samutz again.
public function save_product() {
$data = array();
$error = array();
$config1['upload_path'] = './manager/images/products/';
$config1['allowed_types'] = 'gif|jpeg|png|jpg';
$config1['max_size'] = '3000000';
$config1['max_width'] = '1024';
$config1['max_height'] = '768';
$this->load->library('upload', $config1);
if (!$this->upload->do_upload('product_small_image')){
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($error);
exit();
}
else {
$fdata = $this->upload->data();
$data['product_small_image'] = 'manager/images/products/' . $fdata['file_name'];
}
$config2['upload_path'] = './manager/images/products/large/';
$config2['allowed_types'] = 'gif|jpeg|png|jpg';
$config2['max_size'] = '3000000';
$config2['max_width'] = '1024';
$config2['max_height'] = '768';
$this->upload->initialize($config2);
if (!$this->upload->do_upload('product_large_image')){
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($error);
exit();
}
else {
$fdata = $this->upload->data();
$data['product_large_image'] = 'manager/images/products/large/' . $fdata['file_name'];
}
$data['product_id'] = $this->input->post('product_id', TRUE);
$data['product_name'] = $this->input->post('product_name', TRUE);
$data['category'] = $this->input->post('category', TRUE);
$result = $this->super_admin_model->save_product_detail($data);
$sdata = array();
$sdata['message'] = "Well done!</strong> You successfully add the Product Details.";
$this->session->set_userdata($sdata);
redirect('super_admin/add_product', 'refresh');
}