Insert data And Image upload with codginater
controler page ======>
public function form()
if(isset($_FILES["signature"]["name"]) && empty($_FILES["signature"]["name"])){ $this->session->set_flashdata('error','Please upload signature file .'); redirect($this->agent->referrer()); } if(isset($_FILES["logo"]["name"]) && empty($_FILES["logo"]["name"])){ $this->session->set_flashdata('error','Please upload logo file .'); redirect($this->agent->referrer()); } //define upload folder name $signature_file_uplad_dir ="uploads/signature/"; //get upload file name $signature_file_name =time().basename($_FILES["signature"]["name"]); //file upload path $signature_target_file_upload =$this->system_dir.$signature_file_uplad_dir.$signature_file_name; //get file upload path $signature_file_upload_url =$signature_file_uplad_dir.$signature_file_name; $signature_filetmp_name = $_FILES["signatcherimg"]["tmp_name"]; if(move_uploaded_file($signature_filetmp_name, $signature_target_file_upload)) { $signatcherimg_url=$signature_file_upload_url; }else{ $signatcherimg_url=''; } //system Dir $logo_system_dir =dirname(dirname(__dir__)).'/'; //define upload folder name $logo_file_uplad_dir ="uploads/logo/"; //get upload file name $logo_file_name =time().basename($_FILES["logo"]["name"]); //file upload path $logo_target_file_upload =$logo_system_dir.$logo_file_uplad_dir.$logo_file_name; //get file upload path $logo_file_upload_url =$logo_file_uplad_dir.$logo_file_name; $logo_filetmp_name = $_FILES["logo"]["tmp_name"]; if(move_uploaded_file($logo_filetmp_name, $logo_target_file_upload)) { $logo_url=$logo_file_upload_url; }else{ $logo_url=''; } $data=[ 'user_id'=>$uid, 'name'=>$name, 'company_name'=>$company_name, 'date_issue'=>$date_issue, 'pid'=>$pid, 'number'=>$number, 'gst_number'=>$gst_number, 'email'=>$email, 'url'=>$url, 'gst_charges'=>$gst_charges, 'signatcherimg'=>$signatcherimg_url, 'logo'=>$logo_url, 'subtotal'=>$subtotal, 'address'=>$address, 'tax_rate'=>$tax_rate, 'total_tax'=>$total_tax, 'discount'=>$discount, 'currency'=>$currency, 'zipcode'=>$zipcode, 'country'=>$country, 'bill_name'=>$bill_name, 'bill_email'=>$bill_email, 'bill_zipcode'=>$bill_zipcode, 'bill_country'=>$bill_country, 'bill_phone'=>$bill_phone, 'bill_address'=>$bill_address, 'option'=>$option, ];
//if the insert has returned true then we show the flash message
$customer_id = $this->customer_model->register($data_to_store);
$this->session->set_flashdata('flash_message_l', 'Your User ID is <b>'.$customer_id.'</b>');
redirect('login_form');
}
}//validation run
// $data['category_list'] = $this->customer_model->get_category_list();
$data['main_content'] = 'form';
$this->load->view('includes/front/front_template', $data);
}
views page===>
<div class="container">
<div class="col-sm-12">
<?php
//flash messages
if($this->session->flashdata('flash_message')){
if($this->session->flashdata('flash_message') == 'updated')
{
echo '<div class="alert alert-success">';
echo '<a class="close" data-dismiss="alert">×</a>';
echo '<strong>Well done!</strong> Registered successfully.';
echo '</div>';
} else{
echo '<div class="alert alert-danger">';
echo '<a class="close" data-dismiss="alert">×</a>';
echo '<strong>Oh snap!</strong> change a few things up and try submitting again.';
echo '</div>';
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<?php
echo validation_errors();
?>
<p><label></label>
<input type="text" name="name" class="form-control input-empty" placeholder="Name"value=""></p>
<p><label></label>
<input type="number" name="phonenub" class="form-control input-empty" placeholder="Phone nub" value=""></p>
<p><label></label>
<input type="email" name="email" class="form-control input-empty" placeholder="Email"></p>
<p><label></label>
<input type="password" name="password" class="form-control input-empty" placeholder="Password" ></p>
<p><label></label>
<input type="text" min="1" maxlength="10" name="website" class="form-control input-empty"placeholder="Website" value=""></p>
<p><label></label>
<input type="text" min="1" maxlength="10" name="message" class="form-control input-empty" placeholder="message"value=""></p>
<input type="file" class="input_field" name="image_path">
<button type="submit" name="btn">Submit</button>
</form>
</div>
</div>
Comments
Post a Comment