php - I can't get Codeigniter's file upload feature to work -


i tried going through codeigniter documentation , example in stackoverflow find solution problem didnt help. here codes have uploading image. using upload library through autoload.

this function in controller:

public function do_upload()     {       $config['upload_path'] = './assets/dorm_images';     $config['allowed_types'] = 'jpg|png';     $config['max_size'] = '100';     $config['max_width']  = '1024';     $config['max_height']  = '768';     $config['remove_spaces']  = true;      $this->load->library('upload', $config);     $this->upload->do_upload("userfile");  } 

this form submitted:

<?php $attributes = array('id' => 'listing_form'); echo form_open_multipart('dorm/list_dorm',$attributes);?>   <input type="text" name='name' placeholder='name'><br>  <input type="text" name='description' placeholder='description'><br>  <input type="text" name='price' placeholder='price ($)'><br>  <input type="file" name="userfile" class='btn btn-success btn-mini' size="20" /><br>  <input type="submit" value='list item' class='btn btn-warning' id='submit'> </form> 

here function triggered @ form submission:

public function list_dorm(){         $this->check_logged_in();         $this->load->library('form_validation');         $this->form_validation->set_rules('name','name', 'required');         $this->form_validation->set_rules('condition','condition', 'required');         $this->form_validation->set_rules('category','condition', 'required');         $this->form_validation->set_rules('price','price', 'required|is_natural_no_zero');         $this->form_validation->set_message('is_natural_no_zero', 'the price field must whole number.');           $data=array();         $view_data=array();          $this->load->model('dorm_model');          if($this->form_validation->run() === false ){              $errors=validation_errors();             $data['insert_errors']='<div class="alert alert-danger"><p>'.$errors.'</p></div>';          }         else{         $user_session=$this->session->userdata('user_session');             $user_id=$user_session['id'];              $data['user_id']=$user_id;         $data['name']=$this->input->post('name');             $data['image_path']='/assets/dorm_images/x.jpg';         $data['description']=$this->input->post('description');         $data['price']=$this->input->post('price');         $data['created_at']=date("y-m-d h:i:s");          $this->do_upload();          $this->load->model('dorm_model');         $this->dorm_model->list_dorm($data);           $data['success']='"'.$data['name'].'" listed sale.';             }          echo json_encode($data);     } 


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -