emprit

upload banyak

Dec 8th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.47 KB | None | 0 0
  1. -------------------HELPER--------------------
  2. function multiple_upload($upload_dir = 'uploads', $config = array())
  3. {
  4. $CI = &get_instance();
  5. $files = array();
  6.  
  7. if (empty($config)) {
  8. $config['upload_path'] = realpath($upload_dir);
  9. $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png|pdf';
  10. // $config['max_size'] = '2048';
  11. }
  12.  
  13.  
  14.  
  15. $errors = false;
  16. $no= $CI->input->post('no_urut');
  17.  
  18. foreach ($_FILES as $key => $value) {
  19.     $nama='GE'.$no.'name_'.mt_rand();
  20. $config['file_name'] = $nama;
  21. $CI->load->library('upload', $config);
  22.  
  23. if (!empty($value['name'])) {
  24. if (!$CI->upload->do_upload($key)) {
  25. $data['upload_message'] = $CI->upload->display_errors(ERR_OPEN, ERR_CLOSE); // ERR_OPEN and ERR_CLOSE are error delimiters defined in a config file
  26. $CI->load->vars($data);
  27.  
  28. $errors = true;
  29. } else {
  30. // Build a file array from all uploaded files
  31.  
  32. $files[] = $CI->upload->data();
  33. }
  34. }
  35. }
  36. if ($errors) {
  37. foreach ($files as $key => $file) {
  38. @unlink($file['full_path']);
  39. }
  40. return $data;
  41. }
  42. return $files;
  43. }
  44. ---------------Controller------------------
  45. function administrasi_tambah() {
  46.                 if($this->session->userdata('sudah_login_pelamar')){
  47.                                 $this->load->helper('basic');
  48.                                 $file = multiple_upload('./kelengkapan_dokumen/');
  49.                                
  50.                                 if ( isset($file['upload_message'])){
  51.                                         print_r($file);exit;
  52.                                         $array = array( 'content' => $this->load->view('akun_pelamar/gagal','',true) );
  53.                    $this->load->view('akun_pelamar/menu', $array);
  54.                                 }else{
  55.                                         $reg['query'] = $this->pelamar_model->tambahkelengkapan();
  56.                                                 if($reg['query']) {
  57.                                                         $array = array( 'content' => $this->load->view('akun_pelamar/sukses','',true) );
  58.                                                 $this->load->view('akun_pelamar/menu', $array);
  59.                                                 }
  60.                                 }
  61.                                
  62.                                 }else {
  63.                         redirect('index/index');
  64.                         }
  65.         }
  66.  
  67. -----------------------MODEL------------------
  68. function tambahkelengkapan() {
  69.         $no= $this->input->post('no_urut');
  70.         $img = $this->upload->data();
  71.     //  var_dump ($path.$img['file_name']); //string(36) "./kelengkapan_dokumen/WaTeRfAL._.jpg"
  72.              
  73.       $query1  = $this->db->query("SELECT * FROM form WHERE type != '0'");
  74.       $result = $query1->result();
  75.      
  76.       $i=0;
  77.       $len=count($result);
  78.  
  79.         $emprit= "INSERT INTO penilaian (no_urut,";
  80.         foreach($result as $row){
  81.             if($i == $len - 1) {           
  82.                 $emprit .= "".$row->nama."";    
  83.                 }else{
  84.                     $emprit .= "".$row->nama.",";  
  85.                     }
  86.                     $i++;
  87.       }
  88.       $emprit .= ") VALUES ('".$_POST['no_urut']."',";
  89.        
  90.         $a=0;
  91.         foreach($result as $row){
  92.             if($a == $len - 1) {
  93.                
  94.                 if($row->type == 'file'){
  95.                     $emprit .= "'".$nama."'";
  96.                 }else{
  97.                     $emprit .= "'".$_POST[$row->nama]."'";     
  98.                         }          
  99.                
  100.                 }else{
  101.                    
  102.                     if($row->type == 'file'){
  103.                     $emprit .= "'".$nama."',";
  104.                 }else{
  105.                 $emprit .= "'".$_POST[$row->nama]."',";
  106.                     }
  107.                 }
  108.                     $a++;
  109.             }
  110.         $emprit .= ");";
  111.       $query = $this->db->query($emprit);
  112.       return $query;
  113.       }
Advertisement
Add Comment
Please, Sign In to add comment