image upload

<form method="POST" action="<?=base_url('_adlottery/addimgtxt')?>" enctype='multipart/form-data'>

<input type="text" name="textname" size="20" />
<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</form>



 public function addimgtxt(){
      $textname = $this->input->post('textname');
        $config['upload_path']          = './uploads/blog_photos/';
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 10000;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;

                $this->load->library('upload', $config);

                if ( ! $this->upload->do_upload('userfile'))
                {
                        $error = array('error' => $this->upload->display_errors());
echo $error;
//                        $this->load->view('upload_form', $error);
                }
                else
                {
                     $blog_image = $this->upload->data();
                   $data = array('usertext'=>$textname,
                                  'userfile' => 'uploads/blog_photos/' . $blog_image['raw_name'] . $blog_image['file_ext']
                );
//                        $data = array('upload_data' => $this->upload->data());
                        $this->db->insert('imgandtext', $data);
//                        $this->load->view('upload_success', $data);
                }
  }

No comments:

Post a Comment