Welcome Guest, Not a member yet? Register   Sign In
Form Data and File Upload
#3

[eluser]wowdezign[/eluser]
controller function:
Code:
function add(){
    $this->load->library('form_validation');
    $this->load->helper('form');
    $this->form_validation->set_error_delimiters('<div class="errorDiv">','</div>');
    $this->form_validation->set_rules('news_title','Title','required|trim|max_length[63]|xss_clean');
    $this->form_validation->set_rules('active','Active','required|trim|exact_length[1]|xss_clean');
    $this->form_validation->set_rules('news_desc','Description','required|trim|max_length[255]|xss_clean');
    $this->form_validation->set_rules('news_body','Body','required|trim|max_length[65000]|xss_clean');
    $this->form_validation->set_rules('news_month','Month','required|trim|xss_clean');
    $this->form_validation->set_rules('news_date','Date','required|trim|xss_clean');
    $this->form_validation->set_rules('news_year','Year','required|trim|xss_clean');        
    if($this->form_validation->run()==FALSE){            
        $data['token'] = md5(uniqid(mt_rand(),true));
        $this->session->set_userdata('token',$data['token']);
        $data['title'] = $this->Page->title;
        $data['desc'] = $this->Page->desc;
        $data['kw'] = $this->Page->kw;
        $data['body'] = $this->Page->body;
        $data['menu'] = $this->Page->setMenu();
        $data['subMenu'] = $this->Page->childPages;
        $data['newsList'] = $this->MNews->getNewsByUserID($this->session->userdata('user_id'));
        $data['contentView'] = 'admin/news_add';
        $this->load->view('template',$data);
    }else{            
//        Process the submitted form here .......
        if(!(
            ($this->session->userdata('token')==$this->input->post('token')) &&
            ($this->input->post('submit')=='Save News Item'
        ))){
            $this->session->set_flashdata('fail_string','OOPS! There was problem with the form you submitted.');
            redirect('main/logout','refresh');
        }
        $data['token'] = $this->input->post('token');
        $config['upload_path']='./photos/news/';
        $config['allowed_types']='gif|jpg|png';
        $config['max_size']='2000';
        $config['max_width']='5000';
        $config['max_height']='5000';
        $config['remove_spaces']=TRUE;
        $this->load->library('upload', $config);        
        if (!($this->upload->do_upload())){
            $this->session->set_flashdata('fail_string',$this->upload->display_errors());
            redirect('admin/news/add');
        }else{
            $data = array('upload_data'=>$this->upload->data());
            rename($config['upload_path'].$data['upload_data']['file_name'],$ni=$config['upload_path'].md5(date('U').$_SERVER['REMOTE_ADDR']).".jpg");            
            $config['image_library']='gd2';
            $config['source_image']=$ni;
            $config['create_thumb']=FALSE;
            $config['maintain_ratio']=TRUE;
            $config['width']=350;
            $config['height']=350;
            $this->load->library('image_lib', $config);
            $this->image_lib->resize();
            $data['title']=$this->Page->title;
            $data['desc']=$this->Page->desc;
            $data['kw']=$this->Page->kw;
            $data['body']=$this->Page->body;
            $data['menu']=$this->Page->setMenu();
            $data['subMenu']=$this->Page->childPages;
            $data['newsList']=$this->MNews->getNewsByUserID($this->session->userdata('user_id'));
            $data['contentView']='admin/news_add';
            $this->load->view('template',$data);
        }        
    }
}


Messages In This Thread
Form Data and File Upload - by El Forum - 11-30-2009, 03:48 PM
Form Data and File Upload - by El Forum - 11-30-2009, 06:28 PM
Form Data and File Upload - by El Forum - 11-30-2009, 08:57 PM
Form Data and File Upload - by El Forum - 11-30-2009, 08:58 PM
Form Data and File Upload - by El Forum - 12-01-2009, 01:21 AM
Form Data and File Upload - by El Forum - 12-01-2009, 02:39 AM
Form Data and File Upload - by El Forum - 12-01-2009, 07:34 AM
Form Data and File Upload - by El Forum - 12-01-2009, 07:39 AM
Form Data and File Upload - by El Forum - 12-01-2009, 07:41 AM
Form Data and File Upload - by El Forum - 12-01-2009, 07:43 AM
Form Data and File Upload - by El Forum - 12-01-2009, 07:55 AM
Form Data and File Upload - by El Forum - 12-01-2009, 08:17 AM
Form Data and File Upload - by El Forum - 12-01-2009, 08:22 AM
Form Data and File Upload - by El Forum - 12-01-2009, 08:59 AM
Form Data and File Upload - by El Forum - 12-01-2009, 09:20 AM
Form Data and File Upload - by El Forum - 12-01-2009, 10:57 AM
Form Data and File Upload - by El Forum - 12-01-2009, 11:03 AM
Form Data and File Upload - by El Forum - 12-01-2009, 05:43 PM
Form Data and File Upload - by El Forum - 12-02-2009, 05:15 AM
Form Data and File Upload - by El Forum - 01-21-2010, 12:51 AM
Form Data and File Upload - by El Forum - 01-21-2010, 08:29 AM
Form Data and File Upload - by El Forum - 01-21-2010, 08:15 PM
Form Data and File Upload - by El Forum - 12-07-2010, 06:13 AM
Form Data and File Upload - by El Forum - 12-07-2010, 12:08 PM
Form Data and File Upload - by El Forum - 12-07-2010, 07:55 PM
Form Data and File Upload - by El Forum - 12-08-2010, 11:14 AM
Form Data and File Upload - by El Forum - 10-05-2012, 02:38 AM
Form Data and File Upload - by El Forum - 10-05-2012, 02:54 AM
Form Data and File Upload - by El Forum - 10-07-2012, 06:02 PM
Form Data and File Upload - by El Forum - 10-07-2012, 06:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB