emprit

pusing

Dec 10th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. --------------------------Controller-------------------
  2. function administrasi_tambah() {
  3.                 if($this->session->userdata('sudah_login_pelamar')){
  4.                                              
  5.                                 if ( isset($file['upload_message'])){
  6.                                         print_r($file);exit;
  7.                                         $array = array( 'content' => $this->load->view('akun_pelamar/gagal','',true) );
  8.                                              $this->load->view('akun_pelamar/menu', $array);
  9.                                 }else{
  10.                                                                    
  11.                                         $reg['query'] = $this->pelamar_model->tambahkelengkapan();
  12.                                        
  13.                                                 if($reg['query']) {
  14.                                                 $array = array( 'content' => $this->load->view('akun_pelamar/sukses','',true) );
  15.                                                 $this->load->view('akun_pelamar/menu', $array);
  16.                                                 }
  17.                                 }
  18.                                
  19.                                 }else {
  20.                         redirect('index/index');
  21.                         }
  22.         }
  23.  
  24. --------------------Model--------------------
  25. function tambahkelengkapan() {
  26.     $no=$this->input->post('no_urut');
  27.     $config['upload_path']      = './uploads/';
  28.     $config['allowed_types']    = 'gif|jpg|jpeg|jpe|png|pdf';
  29.  
  30.     $this->load->library('upload');
  31.    
  32.     foreach ($_FILES as $key => $value)
  33.     {
  34.         if (!empty($key['name']))
  35.         {
  36.             // ini yang dibutuhkan
  37.             $filename = 'GE'.$no.'name_'.mt_rand();
  38.  
  39.             // ini untuk nama file pada saat upload
  40.             $config['file_name'] = $filename;
  41.  
  42.             $this->upload->initialize($config);
  43.  
  44.             if (!$this->upload->do_upload($key))
  45.             {
  46.                 $errors = $this->upload->display_errors();
  47.  
  48.                 return FALSE;
  49.             }
  50.             else
  51.             {
  52.                 $query1  = $this->db->query("SELECT * FROM form WHERE type != '0'");
  53.       $result = $query1->result();
  54.      
  55.       $i=0;
  56.       $len=count($result);
  57.  
  58.         $emprit= "INSERT INTO penilaian (no_urut,";
  59.         foreach($result as $row){
  60.             if($i == $len - 1) {           
  61.                 $emprit .= "".$row->nama."";    
  62.                 }else{
  63.                     $emprit .= "".$row->nama.",";  
  64.                     }
  65.                     $i++;
  66.       }
  67.       $emprit .= ") VALUES ('".$_POST['no_urut']."',";
  68.        
  69.         $a=0;
  70.         foreach($result as $row){
  71.             if($a == $len - 1) {
  72.                
  73.                 if($row->type == 'file'){
  74.                     $emprit .= "'".$filename."'";
  75.                 }else{
  76.                     $emprit .= "'".$_POST[$row->nama]."'";     
  77.                         }          
  78.                
  79.                 }else{
  80.                    
  81.                     if($row->type == 'file'){
  82.                     $emprit .= "'".$filename."',";
  83.                 }else{
  84.                 $emprit .= "'".$_POST[$row->nama]."',";
  85.                     }
  86.                 }
  87.                     $a++;
  88.             }
  89.         $emprit .= ");";
  90.       $query = $this->db->query($emprit);
  91.       return $query;
  92.       }
  93.             }
  94.         }
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment