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

(This post was last modified: 06-11-2019, 12:57 PM by ciadmin.)

@php_rocs


Buddy, I tried below code as per your advice. But still not working !!


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_title','Villa Title','trim|required|max_length[128]');
 
         // $this->form_validation->set_rules('prop_status','Status','trim|required');
 
          //$this->form_validation->set_rules('prop_type','Type','trim|required');
 
          //$this->form_validation->set_rules('prop_price','Price','trim|required|numeric');
 
          //$this->form_validation->set_rules('prop_sqft','Sqft','trim|required|numeric');
 
          $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');
 
          //$this->form_validation->set_rules('prop_detailed_info','Detailed Info','trim|required|max_length[2000]');
 
          //$this->form_validation->set_rules('prop_status','Current Status','trim|required');




 
          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'));



 
              //$userInfo = array('email'=>$email, 'password'=>getHashedPassword($password), 'roleId'=>$roleId, 'name'=> $name,
 
                                  //'mobile'=>$mobile, 'createdBy'=>$this->vendorId, 'createdDtm'=>date('Y-m-d H:i:s'));

 
               $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);


 
              $this->load->model('property_model');
 
              $result $this->property_model->addNewProperty($propertyInfo);



 
             if($result 0)

 
              {

 
                if (!empty($_FILES)) {
 
                $is_image "Yes There is Image!";
 
                $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 ;
 
                 $imgData = array('path'=>$targetFile,'propertyid'=>$result);
 
                 if(move_uploaded_file($tempFile$targetFile))
 
                 {


 
                     $prop_push $this->property_model->addPropertyImgs($imgData);

 
                 }


 
                }




 
                 //$propertyImgUpload = uploadImages($result);
 
                  $this->session->set_flashdata('success''Successfuly inserted record & .'.$is_image.'. ,Last Insert ID is.'.$result.'. your property!, Our team will contact you shortly');

 
              }
 
              else {
 
                $this->session->set_flashdata('error''The image not posted');

 
              }
 
             }
 
              else
 
              {
 
                  $this->session->set_flashdata('error''Submission of property failed, Contact [email protected] ');
 
              }



 
               }


 
                   else
                        
{
 
                         $this->listProperty();

 
                       }



 
              redirect('/submit-property');






}


}


?>


The output is :
The image not posted
Reply


Messages In This Thread
RE: $_FILES Array getting empty when using $this-&gt;form_validation-&gt;run() - by sarath_unrelax - 06-11-2019, 12:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB