php - file upload not working - Codeigniter -
i have tried upload image it's not working, before adding upload section code working , entries form stored in database form text field not working..
controller-
have tried below code.but not working.please me solve this?
public function index(){ // if(!$this->session->userdata('logged_in')){ // redirect('register/login'); // } $this->form_validation->set_rules('name', 'name', 'required'); $this->form_validation->set_rules('location', 'location', 'required'); $this->form_validation->set_rules('dob', 'dob', 'required'); $this->form_validation->set_rules('height', 'height', 'required'); $this->form_validation->set_rules('weight', 'weight', 'required'); $this->form_validation->set_rules('optselect', 'complexion', 'required'); $this->form_validation->set_rules('email', 'email exists.', 'required'); if($this->form_validation->run() === false){ $this->load->view('templates/pheader'); $this->load->view('profile/aboutme'); $this->load->view('templates/pfooter'); } else { //upload image $path = './assets/uploads/profilepic'; $config['upload_path'] = $path; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 15000; $config['max_width'] = 1920; $config['max_height'] = 1080; $this->load->library('upload', $config); if(!$this->upload->do_upload()){ echo "lol"; echo $this->upload->display_errors(); $this->session->set_flashdata('file_error', $this->upload->display_errors()); $post_image = 'noimage.jpg'; exit(); }else{ $data = array('upload_data' => $this->upload->data()); $post_image = $_files['userfile']['name']; } $this->profile_model->about($post_image); redirect('profile/vabout'); } } view-
<div class="form-group"> <label class="col-md-3 text-right">upload profile pic:</label> <div class="col-md-9"> <input type="file" name="userfile" id="userfile" size="20" /> </div> </div> model-
public function about($post_image){ $data = array( 'name' => $this->input->post('name'), 'location'=>$this->input->post('location'), 'dob' => $this->input->post('dob'), 'optradio' => $this->input->post('optradio'), 'height'=>$this->input->post('height'), 'weight'=>$this->input->post('weight'), 'optselect'=>$this->input->post('optselect'), 'email' => $this->input->post('email'), 'web'=>$this->input->post('web'), 'awards'=>$this->input->post('awards'), 'cw'=>$this->input->post('cw'), 'pp'=>$this->input->post('pp'), 'youtube'=>$this->input->post('youtube'), 'fb'=>$this->input->post('fb'), 'ld'=>$this->input->post('ld'), 'tw'=>$this->input->post('tw'), 'insta'=>$this->input->post('insta'), 'image'=> $post_image ); return $this->db->insert('profile', $data); }
try this
<form enctype="multipart/form-data" method="post" >
Comments
Post a Comment