06-11-2019, 04:58 AM
(This post was last modified: 06-11-2019, 06:56 AM by ciadmin.)
Hello Everybody,
I have a controller called Home.php & I have method called addProperty() here process the image upload. But the problem is when i use the image upload code after $this->form_validation->run() , its not working.
But without $this->form_validation->run() , the image upload working. When i use the image upload code after the $this->form_validation->run() the image is not getting uploaded.
PHP Code: 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() == FALSE) { $this->listProperty(); } else {
$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"; $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 ; if(move_uploaded_file($tempFile, $targetFile)) {
$imgData = array('path'=>$targetPath,'propertyid'=>$result); $prop_push = $this->property_model->addPropertyImgs($imgData);
}
} }
//$propertyImgUpload = uploadImages($result); $this->session->set_flashdata('success', 'Thank you for submiting.'.$result.'. your property!, Our team will contact you shortly');
} else { $this->session->set_flashdata('error', 'Submission of property failed, Contact [email protected] }
redirect('/submit-property');
}
|