Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of Galeri
- *
- * @author windows8.1
- */
- class Materi extends CI_Controller {
- public function __construct() {
- parent::__construct();
- if(!$this->session->has_userdata('nama')){
- redirect('infront');
- }
- }
- public function index() {
- $data['data'] = $this->crud->select_other('materi', 'order by id_materi desc')->result();
- $this->load->view("materi/materi_data", $data);
- }
- public function simpan_materi() {
- $nama_materi = $this->input->post('nama_materi');
- $config['upload_path'] = './assets/document/';
- $config['allowed_types'] = '*';
- $config['max_size'] = '0';
- $config['overwrite'] = true;
- $this->upload->initialize($config);
- if ($this->upload->do_upload('document')) {
- $document = $this->upload->data();
- // echo $document['file_name'];
- $data = array(
- 'nama_materi' => $nama_materi,
- 'document' => $document['file_name'],
- );
- } else {
- $data = array(
- 'nama_materi' => $nama_materi,
- );
- // echo $this->upload->display_errors();
- }
- $this->crud->insert('materi', $data);
- }
- function hapus_materi() {
- $id = $this->input->post('id');
- $file = $this->input->post('file');
- // unlink(("./assets/document/$file"));
- $this->crud->delete('materi', 'id_materi', $id);
- echo "Data Berhasil Dihapus...";
- }
- function select_materi_id($id) {
- $data = $this->crud->select_id('materi', 'id_materi', $id)->row();
- echo json_encode($data);
- }
- function update_materi() {
- $id = $this->input->post("id");
- $file_name = $this->input->post("materi");
- $nama_materi = $this->input->post('nama_materi');
- $seo = strtolower(str_replace(" ", "-", $nama_materi));
- $config['upload_path'] = './assets/document/';
- $config['allowed_types'] = 'doc|pdf|xls';
- $config['max_size'] = '0';
- $config['overwrite'] = true;
- $this->upload->initialize($config);
- if ($this->upload->do_upload('document')) {
- $document = $this->upload->data();
- $data = array(
- 'nama_materi' => $nama_materi,
- 'document' => $document['file_name'],
- );
- } else {
- $data = array(
- 'nama_materi' => $nama_materi,
- );
- }
- $this->crud->update('materi', $data, 'id_materi', $id);
- echo "Data Berhasil Disimpan!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement