Last active
December 4, 2020 03:03
-
-
Save hid0/909098b53354c58b3dd438303cc465c8 to your computer and use it in GitHub Desktop.
example code for upload image to db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php defined('BASEPATH') OR exit('No direct script access allowed'); | |
| class Registrasi extends CI_Controller { | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| $this->load->model('Model_data', 'Data'); | |
| } | |
| public function index() | |
| { | |
| $data['web_ppdb'] = $this->db->get_where('tbl_web', "id_web='1'")->row(); | |
| if ($data['web_ppdb']->status_ppdb == 'tutup') { | |
| redirect('404'); | |
| } | |
| // $this->form_validation->set_rules('nama_lengkap', 'Nama Lengkap', 'trim|required|min_length[4]'); | |
| // $this->form_validation->set_rules('sekolah_asal', 'Sekolah Asal', 'trim|required|min_length[6]'); | |
| // $this->form_validation->set_rules('ortu', 'Orangtua', 'trim|required|min_length[4]'); | |
| // $this->form_validation->set_rules('wa_ortu', 'No. WA Orangtua', 'trim|numeric|min_length[11]'); | |
| // if ($this->form_validation->run() == false) { | |
| // $this->load->view('web/index', $data); | |
| // } else { | |
| // $this->prereg(); | |
| // } | |
| $this->load->view('web/index', $data); | |
| if (isset($_POST['regNew'])) { | |
| $this->prereg(); | |
| } | |
| } | |
| function register() | |
| { | |
| $nama = $this->input->post('nama_lengkap'); | |
| $asal = $this->input->post('sekolah_asal'); | |
| $ortu = $this->input->post('ortu'); | |
| $nowa = $this->input->post('wa_ortu'); | |
| // $tf = $_FILES['bukti_tf']['name']; | |
| $dummy = array( | |
| 'nama' => $nama, | |
| 'asal_sekolah' => $asal, | |
| 'ortu' => $ortu, | |
| 'wa_ortu' => $nowa, | |
| ); | |
| $config['upload_path'] = './uploads/tf/'; | |
| $config['allowed_types'] = 'jpeg|jpg|png'; | |
| $config['max_size'] = 2048; // 2 MB | |
| $config['file_name'] = 'tf-'.date('ymd'); | |
| // $this->load->library('upload', $config); | |
| $this->upload->initialize($config); | |
| if (!empty($_FILES['bukti_tf']['name'])) { | |
| if ($this->upload->do_upload('bukti_tf')) { | |
| $data = $this->upload->data(); | |
| $dummy['bukti_tf'] = $data['file_name']; | |
| $this->db->insert('tb_pd', $dummy); | |
| $this->session->set_flashdata('msg', '<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Berhasil Mendaftar!</div>'); | |
| } else { | |
| $this->session->set_flashdata('msg', '<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'.$this->upload->display_errors().'</div>'); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment