2015-09-24 51 views
0
public function store(){        
     $id=$this->input->post('id'); 
     $_POST['date_created']=date('Y-m-d');  
     if ($this->form_validation->run('registration') === TRUE) 
     {     
      $_POST['password']= md5($_POST['password']); 
      if(!empty($_FILES['profile_img']['name'])) 
      {    
       echo 'file set ..1<br>'; 
       if(!$this->upload->do_upload('profile_img')) 
       {         
        echo 'file uploading failed ..2'; 
        $error = $this->upload->display_errors(); 
        echo $error; 
        //here its not load the view. 
        $this->template->load('templates/template','emp/add-emp',$error); 

       } 
       else 
       { 
        $img = $this->upload->data(); 
        $file_name ='images/'.$img['file_name']; 
        $data= elements(array('fname','lname','email','password','state','city','mobile','emp_role','profile_img','date_created'),$_POST,$file_name);      
       }   
      } 
      else 
      { 
       echo 'file not set..3'; 
       $data= elements(array('fname','lname','email','password','state','city','mobile','emp_role','date_created'), $_POST);      
      } 

      if(empty($id)){ 
        echo 'Add data ..4'; 
        $this->emp_model->set($data); 
        // $this->crud->insert('info',$data); 
        echo '<script type="text/javascript">alert("Inserted Succesfully ");</script>'; 
        redirect('employee/add','refresh'); 
      } 
      else{ 
        echo 'Update data ..5'; 
        $this->emp_model->set($data,$id); 
        // update('info', $data, 'id', $id); 
        //$this->crud->update('info',$data,'id',$id); 
        echo '<script type="text/javascript">alert("Updated Succesfully ");</script>'; 
        redirect('employee','refresh'); 
       }  
     } 
     else 
     {    
      if(empty($id)){      
       echo 'add data validation falid ..'; 
       $this->add(); 
      } 
      else{ 
       echo 'edit data validation falid ..'; 
       $this->edit($id);      
      }   
     } 
    } 

問題是,當文件上傳失敗手段當文件不是圖片或excced文件來限制它進入顯示錯誤的功能,但我不能加載我的看法...... 所以請告訴我應該有什麼問題?CI中的圖片上傳與驗證

+0

你們是不是要簡單地顯示驗證錯誤或你想重定向? – Kisaragi

+0

沒有我試圖重定向.. –

+0

temprory我回聲$誤差 –

回答

2

使用flashdata和重定向可以重定向你按住你的錯誤信息爲下一個請求:

if(! $this->upload->do_upload($file_name){ 
     $error = $this->upload->display_errors(); 
     $this->session->set_flashdata('error', '$error'); 
     redirect('/somewhere', 'refresh'); 
    } 
+0

好的,謝謝你這 ,但你可以找到有什麼問題.. –