Welcome Guest, Not a member yet? Register   Sign In
$_FILES Array getting empty when using $this->form_validation->run()
#24

(This post was last modified: 06-12-2019, 04:17 AM by hc-innov.)

Don't remove everything in your controller : it can't work...
your controller with change try and post the result):
PHP Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class : Login (LoginController)
 * Login class to control to authenticate user credentials and starts user's session.
 * @author : Kishor Mali
 * @version : 1.1
 * @since : 15 November 2016
 */
class Home extends CI_Controller
{
 
   /**
     * This is default constructor of the class
     */
 
   public function __construct()
 
   {
 
     parent::__construct();
 
     $this->load->model('property_model');

 
    }

 
   /**
     * Index Page for this controller.
     */
 
   public function index()
 
   {
 
       $data = array('title'=> 'Vierra Property Broker''main_content'=>'home');
 
       $this->load->view('template'$data);

 
   }

 
   /**
     * Loaading the submit property form.
     */

 
   public function listProperty()

 
   {

 
     $data = array('title'=> 'Vierra Property Broker - Submit your Property''main_content'=>'submit_property');
 
     $this->load->view('template'$data);




 
   }



 
   function addProperty()
 
   {

 
       $this->load->library('form_validation');
 
          $this->form_validation->set_rules('prop_rooms','Rooms','trim|required|numeric');
 
          $this->form_validation->set_rules('prop_address','Address','trim|required|max_length[200]');
 
          $this->form_validation->set_rules('prop_owner_phone','Mobile Number','required|min_length[10]');
 
          $this->form_validation->set_rules('prop_owner_name','Owner Name','required|min_length[5]');
 
          $this->form_validation->set_rules('prop_owner_email','Owner Email','required|valid_email');

 
          if($this->form_validation->run())
 
          {
 
              $prop_title ucwords(strtolower($this->security->xss_clean($this->input->post('prop_title'))));
 
              $prop_status ucwords(strtolower($this->security->xss_clean($this->input->post('prop_status'))));
 
              $prop_type ucwords(strtolower($this->security->xss_clean($this->input->post('prop_type'))));
 
              $prop_price $this->security->xss_clean($this->input->post('prop_price'));
 
              $prop_sqft $this->security->xss_clean($this->input->post('prop_sqft'));
 
              $prop_rooms $this->security->xss_clean($this->input->post('prop_rooms'));
 
              $prop_address $this->security->xss_clean($this->input->post('prop_address'));
 
              $prop_owner_name $this->security->xss_clean($this->input->post('prop_owner_name'));
 
              $prop_owner_email $this->security->xss_clean($this->input->post('prop_owner_email'));
 
              $prop_owner_phone $this->security->xss_clean($this->input->post('prop_owner_phone'));
 
              $prop_detailed_info $this->security->xss_clean($this->input->post('prop_detailed_info'));
 
              $prop_current_status $this->security->xss_clean($this->input->post('prop_current_status'));
 
               $propertyInfo = array('title'=>$prop_title'status'=>$prop_status'type'=>$prop_type'price'=>$prop_price,
 
                                     'sqft'=>$prop_sqft'rooms'=>$prop_rooms'address'=>$prop_address'name'=>$prop_owner_name,
 
                                     'email'=>$prop_owner_email'phone'=>$prop_owner_phone'detailedInfo'=>$prop_detailed_info,
 
                                     'currentStatus'=>$prop_current_status);
 
              $result $this->property_model->addNewProperty($propertyInfo);
 
              if (!empty($_FILES)) {
 
                  $count_img count($_FILES['file']['name']);
 
                  foreach($_FILES['file']['tmp_name'] as $key => $value) {

 
                   $tempFile $_FILES['file']['tmp_name'][$key];
 
                   $fileName $_FILES['file']['name'][$key];
 
                   $targetPath 'property-images/';
 
                   $targetFile $targetPath $fileName ;

 
                   //$this->load->model('user_model');

 
                   $imgData = array('path'=>$targetFile,'propertyid'=>$result);

 
                   if(move_uploaded_file($tempFile$targetFile))
 
                   {
 
                       echo 'Move upload file and add propertyImgs<br>';
 
                       $this->property_model->addPropertyImgs($imgData);
 
                   }
 
                  }
 
              } else {
 
                  echo '$_FILES is empty';
 
              }
die();
 
            }
 
              if($result 0)
 
              {
 
                 //$propertyImgUpload = uploadImages($result);
 
                  $this->session->set_flashdata('success''Thank you for submiting your property with us!, Our team will contact you shortly');
 
              }
 
              else
 
              {
 
                  $this->session->set_flashdata('error''Submission of property failed, Contact [email protected]');
 
              }
 
              if (!empty($_FILES)) {
 
                  $count_img count($_FILES['file']['name']);
 
                  foreach($_FILES['file']['tmp_name'] as $key => $value) {

 
                   $tempFile $_FILES['file']['tmp_name'][$key];
 
                   $fileName $_FILES['file']['name'][$key];
 
                   $targetPath 'property-images/';
 
                   $targetFile $targetPath $fileName ;

 
                   //$this->load->model('user_model');

 
                   $imgData = array('path'=>$targetFile,'propertyid'=>$result);

 
                   if(move_uploaded_file($tempFile$targetFile))
 
                   {
 
                       $this->property_model->addPropertyImgs($imgData);
 
                   }
 
                  }
 
              }
 
              redirect('/submit-property');
 
          }
 
        }


function 
check_captcha()
{


 
  if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
 
    $gCaptcha $_POST['g-recaptcha-response'];
 
   // Google reCAPTCHA API secret key
 
  $secretKey '6LekZagUAAAAALlguY5sjircXO6Adre6BDDHQWV_';

 
  // Verify the reCAPTCHA response
 
  $verifyResponse file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$gCaptcha);

 
  // Decode json data
 
  $responseData json_decode($verifyResponse);

 
  print_r($responseData);

}
else {
//$this->load->view('upload_index');

}

}


?>
Reply


Messages In This Thread
RE: $_FILES Array getting empty when using $this-&gt;form_validation-&gt;run() - by hc-innov - 06-12-2019, 04:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB