sebuahhobi

file foto tidak ada setelah di inputkan

Oct 5th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.64 KB | None | 0 0
  1. //views
  2. <div class="form-group">
  3.                         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="char">Foto <?php echo form_error('foto'); echo $this->session->flashdata('foto');?> </label>
  4.                         <div class="col-md-6 col-sm-6 col-xs-12">
  5.                             <input type="file" name="foto" id="foto" required onchange="previewImage();" value="<?php echo $foto;?>">
  6.                            
  7.                             <img id="image-preview" alt="image preview"/>
  8.                         </div>
  9.                     </div>
  10.                     <style type="text/css">
  11.                         #image-preview{
  12.                             display:none;
  13.                             width : 100px;
  14.                             height:120px;
  15.                         }
  16.                     </style>
  17.                     <script>
  18.                         function previewImage() {
  19.                             document.getElementById("image-preview").style.display = "block";
  20.                             var oFReader = new FileReader();
  21.                              oFReader.readAsDataURL(document.getElementById("foto").files[0]);
  22.                          
  23.                             oFReader.onload = function(oFREvent) {
  24.                               document.getElementById("image-preview").src = oFREvent.target.result;
  25.                             };
  26.                         };
  27.                     </script>
  28.  
  29. //controllel
  30. public function create_action_mhs()
  31.     {
  32.         $config['upload_path']          = './gambar/';
  33.         $config['allowed_types']        = 'gif|jpg|png';
  34.         $config['max_size']             = 10;
  35.         //$config['max_width']            = 1024;
  36.         //$config['max_height']           = 768;
  37.  
  38.         $this->load->library('upload', $config);
  39.  
  40.         $this->rules_mhs();
  41.  
  42.         if ($this->form_validation->run() == FALSE) {
  43.             $this->create_mhs();
  44.         }
  45.         elseif(! $this->upload->do_upload($this->input->post('foto',TRUE))){
  46.             $error9 = array('foto' => $this->upload->display_errors());
  47.             $this->session->set_flashdata($error9);
  48.             //redirect(site_url('super_admin/create_mhs'));
  49.  
  50.              $this->create_mhs();
  51.         }
  52.         else {
  53.             date_default_timezone_set('Asia/jakarta');
  54.             $user=$this->ion_auth->user()->row();
  55.             if(empty($this->input->post('tgl_lahir',TRUE)))
  56.                 $tgl="";
  57.             else
  58.                 $tgl=date('Y-m-d', strtotime($this->input->post('tgl_lahir',TRUE)));
  59.            
  60.              $this->upload->data();
  61.  
  62.             $data = array(
  63.                 'nama'            => $this->input->post('nama',TRUE),
  64.                 'npm'             => $this->input->post('npm',TRUE),
  65.                 'fakultas'        => $this->input->post('fakultas',TRUE),
  66.                 'jurusan'         => $this->input->post('jurusan',TRUE),
  67.                 'semester'        => $this->input->post('semester',TRUE),
  68.                 //'kamar'           => $this->input->post('kamar',TRUE),
  69.                 //'operator' => $this->input->post('operator',TRUE),
  70.                 'operator'        => $user->first_name.' '.$user->last_name,
  71.                 'noHP'            => $this->input->post('noHP',TRUE),
  72.                 'j_k'             => $this->input->post('j_k',TRUE),
  73.                 'ttl'             => $this->input->post('ttl',TRUE),
  74.                 'sertifikat_ldik' => $this->input->post('sertifikat_ldik',TRUE),
  75.                 'foto'            => $this->input->post('foto',TRUE),
  76.                 'bahasa'          => implode(" ",$this->input->post('bahasa',TRUE)),
  77.                 'hobi'            => $this->input->post('hobi',TRUE),
  78.                 'keahlian'        => $this->input->post('keahlian',TRUE),
  79.                 'cita_cita'       => $this->input->post('cita_cita',TRUE),
  80.                 'tgl_lahir'       => $tgl,
  81.             );
  82.             $this->admin_model->insert($data);
  83.             //kamar_mhs
  84.             /*$ambil_id_mhs   = $this->db->get_where('daftar_mhs',array('npm'=>$this->input->post('npm',TRUE)));
  85.             $ambil_id_kamar = $this->db->get_where('kamar',array('kamar'=>$this->input->post('kamar',TRUE)));
  86.             foreach ($ambil_id_mhs->result() as $main){
  87.                 foreach ($ambil_id_kamar->result() as $mhs){
  88.                     $kamar_id=$mhs->id;
  89.                     $mhs_id=$main->id;
  90.  
  91.                 }
  92.             }
  93.            
  94.             $data_kamar=array(
  95.                 'id_mhs'   => $mhs_id,  
  96.                 'id_kamar' => $kamar_id
  97.             );
  98.              $this->mhs_kamar_model->insert($data_kamar);
  99.             */
  100.              //Data orang tua
  101.              $ambil_id_mhs   = $this->db->get_where('daftar_mhs',array('npm'=>$this->input->post('npm',TRUE)));
  102.             foreach ($ambil_id_mhs->result() as $mhs1){
  103.                     $mhs_id=$mhs1->id;
  104.             }
  105.              $data_orang_tua = array(
  106.         'nama_Ayah' => $this->input->post('nama_Ayah',TRUE),
  107.         'noHP_Ayah' => $this->input->post('noHP_Ayah',TRUE),
  108.         'nama_Ibu' => $this->input->post('nama_Ibu',TRUE),
  109.         'noHP_Ibu' => $this->input->post('noHP_Ibu',TRUE),
  110.         'provinsi' => $this->input->post('provinsi',TRUE),
  111.         'kab' => $this->input->post('kab',TRUE),
  112.         'kec' => $this->input->post('kec',TRUE),
  113.         'desa' => $this->input->post('desa',TRUE),
  114.         'rt' => $this->input->post('rt',TRUE),
  115.         'id_mhs' => $mhs_id
  116.         );
  117.  
  118.             $this->Data_orang_tua_model->insert($data_orang_tua);
  119.             //END data orang tua
  120.            
  121.             $this->session->set_flashdata('message', 'Create Record Success');
  122.             redirect(site_url('super_admin/mhs_list_ikhwan'));
  123.         }
  124.     }
Add Comment
Please, Sign In to add comment