Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. /**
  10. * Description of Galeri
  11. *
  12. * @author windows8.1
  13. */
  14. class Materi extends CI_Controller {
  15. public function __construct() {
  16. parent::__construct();
  17. if(!$this->session->has_userdata('nama')){
  18. redirect('infront');
  19. }
  20. }
  21.  
  22. public function index() {
  23. $data['data'] = $this->crud->select_other('materi', 'order by id_materi desc')->result();
  24. $this->load->view("materi/materi_data", $data);
  25. }
  26.  
  27. public function simpan_materi() {
  28. $nama_materi = $this->input->post('nama_materi');
  29. $config['upload_path'] = './assets/document/';
  30. $config['allowed_types'] = '*';
  31. $config['max_size'] = '0';
  32. $config['overwrite'] = true;
  33. $this->upload->initialize($config);
  34.  
  35. if ($this->upload->do_upload('document')) {
  36. $document = $this->upload->data();
  37. // echo $document['file_name'];
  38. $data = array(
  39. 'nama_materi' => $nama_materi,
  40. 'document' => $document['file_name'],
  41. );
  42. } else {
  43. $data = array(
  44. 'nama_materi' => $nama_materi,
  45. );
  46. // echo $this->upload->display_errors();
  47. }
  48. $this->crud->insert('materi', $data);
  49. }
  50.  
  51. function hapus_materi() {
  52. $id = $this->input->post('id');
  53. $file = $this->input->post('file');
  54. // unlink(("./assets/document/$file"));
  55.  
  56. $this->crud->delete('materi', 'id_materi', $id);
  57. echo "Data Berhasil Dihapus...";
  58. }
  59.  
  60. function select_materi_id($id) {
  61. $data = $this->crud->select_id('materi', 'id_materi', $id)->row();
  62. echo json_encode($data);
  63. }
  64.  
  65. function update_materi() {
  66. $id = $this->input->post("id");
  67. $file_name = $this->input->post("materi");
  68. $nama_materi = $this->input->post('nama_materi');
  69. $seo = strtolower(str_replace(" ", "-", $nama_materi));
  70. $config['upload_path'] = './assets/document/';
  71. $config['allowed_types'] = 'doc|pdf|xls';
  72. $config['max_size'] = '0';
  73. $config['overwrite'] = true;
  74. $this->upload->initialize($config);
  75.  
  76. if ($this->upload->do_upload('document')) {
  77. $document = $this->upload->data();
  78. $data = array(
  79. 'nama_materi' => $nama_materi,
  80. 'document' => $document['file_name'],
  81. );
  82. } else {
  83. $data = array(
  84. 'nama_materi' => $nama_materi,
  85. );
  86. }
  87. $this->crud->update('materi', $data, 'id_materi', $id);
  88. echo "Data Berhasil Disimpan!";
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement