Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------HELPER--------------------
- function multiple_upload($upload_dir = 'uploads', $config = array())
- {
- $CI = &get_instance();
- $files = array();
- if (empty($config)) {
- $config['upload_path'] = realpath($upload_dir);
- $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png|pdf';
- // $config['max_size'] = '2048';
- }
- $errors = false;
- $no= $CI->input->post('no_urut');
- foreach ($_FILES as $key => $value) {
- $nama='GE'.$no.'name_'.mt_rand();
- $config['file_name'] = $nama;
- $CI->load->library('upload', $config);
- if (!empty($value['name'])) {
- if (!$CI->upload->do_upload($key)) {
- $data['upload_message'] = $CI->upload->display_errors(ERR_OPEN, ERR_CLOSE); // ERR_OPEN and ERR_CLOSE are error delimiters defined in a config file
- $CI->load->vars($data);
- $errors = true;
- } else {
- // Build a file array from all uploaded files
- $files[] = $CI->upload->data();
- }
- }
- }
- if ($errors) {
- foreach ($files as $key => $file) {
- @unlink($file['full_path']);
- }
- return $data;
- }
- return $files;
- }
- ---------------Controller------------------
- function administrasi_tambah() {
- if($this->session->userdata('sudah_login_pelamar')){
- $this->load->helper('basic');
- $file = multiple_upload('./kelengkapan_dokumen/');
- if ( isset($file['upload_message'])){
- print_r($file);exit;
- $array = array( 'content' => $this->load->view('akun_pelamar/gagal','',true) );
- $this->load->view('akun_pelamar/menu', $array);
- }else{
- $reg['query'] = $this->pelamar_model->tambahkelengkapan();
- if($reg['query']) {
- $array = array( 'content' => $this->load->view('akun_pelamar/sukses','',true) );
- $this->load->view('akun_pelamar/menu', $array);
- }
- }
- }else {
- redirect('index/index');
- }
- }
- -----------------------MODEL------------------
- function tambahkelengkapan() {
- $no= $this->input->post('no_urut');
- $img = $this->upload->data();
- // var_dump ($path.$img['file_name']); //string(36) "./kelengkapan_dokumen/WaTeRfAL._.jpg"
- $query1 = $this->db->query("SELECT * FROM form WHERE type != '0'");
- $result = $query1->result();
- $i=0;
- $len=count($result);
- $emprit= "INSERT INTO penilaian (no_urut,";
- foreach($result as $row){
- if($i == $len - 1) {
- $emprit .= "".$row->nama."";
- }else{
- $emprit .= "".$row->nama.",";
- }
- $i++;
- }
- $emprit .= ") VALUES ('".$_POST['no_urut']."',";
- $a=0;
- foreach($result as $row){
- if($a == $len - 1) {
- if($row->type == 'file'){
- $emprit .= "'".$nama."'";
- }else{
- $emprit .= "'".$_POST[$row->nama]."'";
- }
- }else{
- if($row->type == 'file'){
- $emprit .= "'".$nama."',";
- }else{
- $emprit .= "'".$_POST[$row->nama]."',";
- }
- }
- $a++;
- }
- $emprit .= ");";
- $query = $this->db->query($emprit);
- return $query;
- }
Advertisement
Add Comment
Please, Sign In to add comment