Want to Remove Validation in Resume Upload in in codeigniter - php

We are working on Job Scrip. Faces problem in signup page validation. It has on Resume as well. We need to remove the Validation from Upload Resume. How to remove the Validation from the Signup page at upload Resume only. Please help us in this.
Controller is in codeigniter. Help us, we for stuck into this.
$this->form_validation->set_message('is_unique', 'The %s is already taken');
if (empty($_FILES['cv_file']['name']))
$this->form_validation->set_rules('cv_file', 'Resume', 'required');
$this->form_validation->set_error_delimiters('<div class="errowbox"><div class="erormsg">', '</div></div>');
if ($this->form_validation->run() === FALSE) {
$data['cpt_code'] = create_ml_captcha();
$this->load->view('jobseeker_signup_view',$data);
return;
}
$current_date = date("Y-m-d H:i:s");
$job_seeker_array = array(
'first_name' => $this->input->post('full_name'),
'email' => $this->input->post('email'),
'password' => $this->input->post('pass'),
'dob' => $this->input->post('dob_year').'-'.$this->input->post('dob_month').'-'.$this->input->post('dob_day'),
'mobile' => $this->input->post('mobile_number'),
'home_phone' => $this->input->post('phone'),
'present_address' => $this->input->post('current_address'),
'country' => $this->input->post('country'),
'city' => $this->input->post('city'),
'nationality' => $this->input->post('nationality'),
'gender' => $this->input->post('gender'),
'ip_address' => $this->input->ip_address(),
'dated' => $current_date
);
if (!empty($_FILES['cv_file']['name'])){
//$verification_code = md5(time());
$extention = get_file_extension($_FILES['cv_file']['name']);
$allowed_types = array('doc','docx','pdf','rtf','jpg','txt');
if(!in_array($extention,$allowed_types)){
$data['cpt_code'] = create_ml_captcha();
$data['msg'] = 'This file type is not allowed.';
$this->load->view('jobseeker_signup_view',$data);
return;
}
$seeker_id = $this->job_seekers_model->add_job_seekers($job_seeker_array);
$resume_array = array();
$real_path = realpath(APPPATH . '../public/uploads/candidate/resumes/');
$config['upload_path'] = $real_path;
$config['allowed_types'] = 'doc|docx|pdf|rtf|jpg|txt';
$config['overwrite'] = true;
$config['max_size'] = 6000;
$config['file_name'] = replace_string(' ','-',strtolower($this->input->post('full_name'))).'-'.$seeker_id;
$this->upload->initialize($config);
if (!$this->upload->do_upload('cv_file')){
$this->job_seekers_model->delete_job_seeker($seeker_id);
$data['cpt_code'] = create_ml_captcha();
$data['msg'] = $this->upload->display_errors();
$this->load->view('jobseeker_signup_view',$data);
return;
}
$resume = array('upload_data' => $this->upload->data());
$resume_file_name = $resume['upload_data']['file_name'];
$resume_array = array(
'seeker_ID' => $seeker_id,
'file_name' => $resume_file_name,
'dated' => $current_date,
'is_uploaded_resume' => 'yes'
);
}

Remove this
if (empty($_FILES['cv_file']['name']))
$this->form_validation->set_rules('cv_file', 'Resume', 'required');

Related

How to solve error Number: 1048 Column 'photo_pict' cannot be null?

I got this error:
A Database Error Occurred
Error Number: 1048
Column 'photo_pict' cannot be null
INSERT INTO `tester` (`photo_pict`, `press_pict`, `name_pict`) VALUES (NULL, NULL, NULL)
Filename: C:/xampp/htdocs/pretest/system/database/DB_driver.php
Line Number: 691
I'm using CodeIgniter and I'm a beginner programmer.
I was making a register form, all I have to do is just saving the input from the register form to the database. But every data has been saved to database except the data for saving photo to the database.
Code show here
Model :
function insert($data){
$data = array(
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'birthDate' => $data['birthDate'],
'gender' => $data['gender'],
'posisi' => $data['posisi'],
'media_name' => $data['media_name'],
'media_region' => $data['media_region'],
'media_ctgry' => $data['media_ctgry'],
'company_addrss' => $data['company_addrss'],
'website' => $data['website'],
'editor_email' => $data['editor_email'],
'office_phone' => $data['office_phone'],
'office_fax' => $data['office_fax'],
'personal_email' => $data['personal_email'],
'phone_number' => $data['phone_number'],
'working_email' => $data['working_email']
);
$this->db->insert('tester', $data);
}
function upload($data){
$gambar = array(
'photo_pict'=> $data['photo_pict'],
'press_pict'=> $data['press_pict'],
'name_pict'=> $data['name_pict']
);
$this->db->insert('tester', $gambar);
}
function proses_regist(){
return $this->db->insert('tester', $data);
}
}
My Controller :
public function __construct(){
parent :: __construct();
$this->load->model("Model_regist");
$this->load->helper(array('url','form'));
}
public function index(){
$this->load->view('home');
}
function register(){
$gambar = array(
'press_pict'=>$this->upload->data("photo_pict"),
'photo_pict'=>$this->upload->data("press_pict"),
'name_pict'=>$this->upload->data("name_pict")
);
$data = array(
'first_name' => $this->input->post("first_name"),
'last_name' => $this->input->post("last_name"),
'birthDate' => $this->input->post("birthDate"),
'gender' => $this->input->post("gender"),
'posisi' => $this->input->post("posisi"),
'media_name' => $this->input->post("media_name"),
'media_region' => $this->input->post("media_region"),
'media_ctgry' => $this->input->post("media_ctgry"),
'company_addrss' => $this->input->post("company_addrss"),
'website' => $this->input->post("website"),
'editor_email' => $this->input->post("editor_email"),
'office_phone' => $this->input->post("office_phone"),
'office_fax' => $this->input->post("office_fax"),
'personal_email' => $this->input->post("personal_email"),
'phone_number' => $this->input->post("phone_number"),
'working_email' => $this->input->post("working_email")
);
$this->Model_regist->insert($data);
$this->Model_regist->upload($gambar);
$this->index();
}
private function uploadImage(){
$config['upload_path'] = './gambar/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $this->product_id;
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = true;
$nama_file = "gambar_".time();
$config['file_name'] = $nama_file;
$this->load->library('upload', $config);
if( ! $this->upload->do_upload('berkas')){
$error = array('error' => $this->upload->display_errors());
}else{
$this->upload->data();
}
$this->Model_regist->upload($gambar);
$this->Model_regist->insert($data);
$this->index();
}
I expect the photo that has been chosen can be saved in the database and can be saved in the file that I have made before. The file name is gambar.

how to insert the filename in database and file in folder using codeignator?

I am having a problem with inserting file_path to database and file upload in folder using Codeigniter, I have a form field where user can upload any jpg|png|gif file. But how will I get the file_path of that particular file uploaded and insert it into database and file are stored in floder.
my controller code
public function enqry(){
$data = array();
$postData = array();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
//if add request is submitted
if ( ! $this->upload->do_upload('upload')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('imageUploadForm', $error);
}else {
print_r('Image Uploaded Successfully.');
}
if($this->input->post('postSubmit')){
//form field validation rules
$this->form_validation->set_rules('name', 'post name', 'required');
$this->form_validation->set_rules('email', 'post email', 'required');
$this->form_validation->set_rules('mobile', 'post number', 'required');
$this->form_validation->set_rules('nationality', 'post nationality', 'required');
$this->form_validation->set_rules('location','post location','required');
//prepare post data
$postData = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'mobile' => $this->input->post('mobile'),
'nationality' => $this->input->post('nationality'),
'location'=>$this->input->post('location'),
'statuse' => '0',
'created_at' => date("Y-m-d H:i:s")
/*'passport_details'=>$this->input->post('passport_details')*/
);
//validate submitted form data
if($this->form_validation->run() == true){
//insert post data
$insert2 = $this->user_mod->insert_enq($postData);
if($insert2){
$this->session->set_userdata('success_msg', 'Post has been added successfully.');
redirect('/User_con/log/');
}else{
$data['error_msg'] = 'Some problems occurred, please try again.';
}
}
}
$data['post'] = $postData;
$data['title'] = 'Create Post';
}
//load the add page view
public function log_enq(){
$this->load->view('templates/header');
$this->load->view('enquiry_reg');
$this->load->view('templates/footer');
}
My view code
<div class="form-group">
<label for="title">File Upload</label>
<input type="file" name="upload" placeholder="upload">
</div>
My model code
public function insert_enq($data = array()) {
$insert2 = $this->db->insert('tbl_enquiry', $data);
if($insert2){
return $this->db->insert_id();
}else{
return false;
}
}
if (!$this->upload->do_upload('upload')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('imageUploadForm', $error);
}
else {
$data = $this->upload->data('file_name');
$image = 'your_path'.$data;
}
and add $image variable to your your query like
$arrayName = array(
'imapge' => $image,
'more_column' => $more_column_values);
public function enqry(){
$data = array();
$postData = array();
$postData['upload_path'] = './uploads/';
$postData['allowed_types'] = 'gif|jpg|png';
$postData['max_size'] = 10240;
$this->load->library('upload', $postData);
if (!$this->upload->do_upload('upload')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('user_con/error', $error);
}
else {
$data = $this->upload->data('file_name');
$image = 'your_path'.$data;
}
if($this->input->post('postSubmit')){
$this->form_validation->set_rules('name', 'post name', 'required');
$this->form_validation->set_rules('email', 'post email', 'required');
$this->form_validation->set_rules('mobile', 'post number', 'required');
$this->form_validation->set_rules('nationality', 'post nationality', 'required');
$this->form_validation->set_rules('location','post location','required');
$postData = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'mobile' => $this->input->post('mobile'),
'nationality' => $this->input->post('nationality'),
'location'=>$this->input->post('location'),
'statuse' => '0',
'created_at' => date("Y-m-d H:i:s"),
'upload' => $image
);
if($this->form_validation->run() == true){
$insert2 = $this->user_mod->insert_enq($postData);
if($insert2){
$this->session->set_userdata('success_msg', 'Post has been added successfully.');
redirect('/User_con/log/');
}else{
$data['error_msg'] = 'Some problems occurred, please try again.';
}
}
}
$data['post'] = $postData;
$data['title'] = 'Create Post';
}
$config = array(
'upload_path' =>'./uploads/',
'allowed_types' =>'jpg|jpeg|png|gif',
'max_size' => '5000KB');
$this->load->library('upload',$config);
$this->upload->initialize($config);
Replace this code your code....and cheack......

Data update is not working without profile picture

In php when I am updating user info into database with profile image then updation is working but when I'm not selecting image then the update is not working.
Here is my controller:
public function editvendor($id = '') {
$this->authAdLogin();
if ($id == '') {
redirect(admin_url() . 'vendorlisting');
} else if ($this->db->where('id', $id)->get('tbl_vendor')->num_rows() == 0) {
redirect(admin_url() . 'vendorlisting');
} else {
$data['vendor_data'] = $this->db->where('id', $id)->get('tbl_vendor')->result_array();
$vendor_data = $data['vendor_data'];
$this->form_validation->set_rules('contact_name', 'Name', 'trim|xss_clean|required');
$this->form_validation->set_rules('contact_mobile', 'Mobile Number', 'trim|xss_clean|required|numericmin_length[10]|max_length[10]');
$this->form_validation->set_rules('contact_land', 'Landline Number', 'trim|xss_clean|numeric');
$this->form_validation->set_rules('contact_email', 'Email', 'trim|xss_clean|required|valid_email');
$this->form_validation->set_rules('incorporation_date', 'Incorporation Date', 'trim|xss_clean|required');
$this->form_validation->set_rules('pancard_no', 'Pan Card', 'trim|xss_clean|required');
$this->form_validation->set_rules('tan_no', 'Tan Number', 'trim|xss_clean|required');
$this->form_validation->set_rules('tin_no', 'Tin Number', 'trim|xss_clean|required');
$this->form_validation->set_rules('service_no', 'Service Number', 'trim|xss_clean|required');
if ($this->form_validation->run() == false) {
$this->load->view('admin/header');
$this->load->view('admin/sidemenu');
$this->load->view('admin/editvendor', $data);
} else {
$id = $vendor_data[0]['id'];
$upload_dir = './uploads/' . $vendor_data[0]['vendor_id'];
if (!is_dir($upload_dir)) {
mkdir($upload_dir);
}
if (isset($_FILES['profile_pic']['name'])) {
$config['upload_path'] = './uploads/' . $vendor_data[0]['vendor_id'];
$config['allowed_types'] = 'gif|jpg|png';
/* $config['max_size'] = '1000000';
$config['max_width'] = '10240000';
$config['max_height'] = '7680000'; */
$config['file_name'] = "prof_" . rand(1, 5000);
$this->load->library('upload');
$this->upload->initialize($config);
if (!$this->upload->do_upload('profile_pic')) {
$error = $this->upload->display_errors();
$this->session->set_flashdata('ppic_error', $error);
redirect(admin_url() . 'editvendor');
} else {
$data = $this->upload->data();
$prof_pic = $data['file_name'];
}
} else {
$prof_pic = $vendor_data[0]['profile_pic'];
}
$update_data = array(
'contact_name' => $this->input->post('contact_name'),
'contact_mobile' => $this->input->post('contact_mobile'),
'contact_land' => $this->input->post('contact_land'),
'contact_email' => $this->input->post('contact_email'),
'mailing_address' => $this->input->post('mailing_address'),
'incorporation_date' => $this->input->post('incorporation_date'),
'pancard_no' => $this->input->post('pancard_no'),
'tan_no' => $this->input->post('mailing_address'),
'mailing_address' => $this->input->post('tan_no'),
'tin_no' => $this->input->post('tin_no'),
'service_no' => $this->input->post('service_no'),
'web_url' => $this->input->post('web_url'),
'business_address' => $this->input->post('business_address'),
'other_certificates' => $this->input->post('other_certificates'),
'facebook_link' => $this->input->post('facebook_link'),
'twitter_link' => $this->input->post('twitter_link'),
'linkedin_link' => $this->input->post('linkedin_link'),
'googleplus_link' => $this->input->post('googleplus_link'),
'about_company' => $this->input->post('about_company'),
'industry_segment' => $this->input->post('industry_segment'),
'ayurveda' => $this->input->post('ayurveda'),
'homeopathy' => $this->input->post('homeopathy'),
'unani' => $this->input->post('unani'),
'profile_pic' => $prof_pic,
);
$this->db->where('id', $id);
$this->db->update('tbl_vendor', $update_data);
$this->session->set_flashdata('vendor_edit', 'Successfully updated.');
redirect(admin_url() . 'editvendor/' . $id);
}
}
}
Please
provide any solution.

validating the captcha codeigniter

hey guys im trying to validate a captcha code in codeigniter. is there an easy way to validate the captcha? here is my code and it is not working because everytime it loads the page it will call a new captcha which will replace the word in the session.
public function index() {
$originalString = array_merge(range(0,9), range('a','z'), range('A', 'Z'));
$originalString = implode("", $originalString);
$captcha = substr(str_shuffle($originalString), 0, 6);
$vals = array(
'word' => $captcha,
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'font_path' => './system/fonts/texb.ttf',
'img_width' => 150,
'img_height' => 50,
'expiration' => 7200 );
$cap = create_captcha($vals);
$captchaImage = $cap['image'];
$this->session->set_userdata($cap);
if(isset($_POST['register'])) {
$this->form_validation->set_rules('firstName', 'First Name', 'required');
$this->form_validation->set_rules('lastName', 'Last Name', 'required');
$this->form_validation->set_rules('emailAddress', 'Email', 'required|valid_email');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[6]');
$this->form_validation->set_rules('password', 'Password', 'required|matches[confirm-password]|min_length[6]');
$this->form_validation->set_rules('confirm-password', 'Password Confirm', 'required');
$this->form_validation->set_rules('secretquestion', 'Secret Question', 'required');
$this->form_validation->set_rules('answer', 'Answer', 'required');
$this->form_validation->set_rules('inputCode', 'Captcha', 'required|');
if ($this->form_validation->run() == TRUE) {
$user = $this->Account_Model->validation($_POST['username']);
if($_POST['inputCode'] != $this->session->userdata('word')){
echo $_POST['inputCode'] .' = ' .$this->session->userdata('word');
$this->_error = 'Code does not match the image';
} else {
if(empty($user)) {
$this->load->library('upload');
$accountId = $this->Account_Model->addUser($_POST);
$config['upload_path'] = './assets/uploads/avatars';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $_POST['username'];
$this->upload->initialize($config);
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('avatar'))
{
$error = array('error' => $this->upload->display_errors());
}
if($accountId){
$this->_body = array(
'username' => $_POST['username'],
'email' => $_POST['emailAddress'],
'secretQuestion' => $_POST['secretquestion'],
'answer' => $_POST['answer'],
'captchaImage' => $captchaImage
);
$this->_template = 'register_success';
return $this->_renderPage();
}
}
}
}
}
$this->_body = array(
'secretQuestions' => $this->questions,
'captchaImage' => $captchaImage,
'error' => $this->_error
);
return $this->_renderPage();
}
is there a better way to do this??.. please help.. tnx in advanced..
Maybe the easiest way would be to not create a new captcha once the user submits the form, or at least not update the session.
if(!$_POST){
$this->session->set_userdata($cap);
}

File not uploading in codeigniter

This is the codeigniter function for file uploading
public function doctor_signup()
{
$this->load->library('encrypt');
$rand = time() . rand(0, 9999);
if($_FILES["file"]["name"]!="")
{
$config['upload_path'] = realpath(dirname(__FILE__)). '/uploads/';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['name']=$rand;
print_r($config);
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
echo $error = array('error' => $this->upload->display_errors());
exit;
}
}
$data = array(
'username' => $_POST['username'],
'password' => $this->encrypt->encode($_POST['password']),
'name' => $_POST['name'],
'address' => $_POST['address'],
'city' => $_POST['city'],
'state' => $_POST['state'],
'photo'=> $rand,
'email' => $_POST['email'],
'date_of_join'=>date('Y-m-d H:m:s'),
'landline' => $_POST['landline'],
'mobile' => $_POST['mobile'],
'specialist' => $_POST['specialist'],
'comments' => $_POST['comments'],
'degree' => $_POST['degree']
);
if( $this->db->insert('doctor_user', $data))
{
$this->load->view('header', $data);
$this->load->view('user_created', $data);
$this->load->view('footer', $data);
}
}
But the file is not uploaded to the upload directory an also not giving any error. The uploads folder in under the home directory. Any suggestion.
Thanks
I think it could be because $config['name'] should be
$config['file_name']
Try renaming this and see if it works. Also you are not using $config['allowed_types'] to specify what files can be uploaded. Otherwise whats to stop someone upload a nasty file?

Categories