Advertisement
Guest User

Contrroller Upload

a guest
Sep 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Upload extends CI_Controller {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->model('MDL_upload');
  9. }
  10.  
  11. public function index()
  12. {
  13.  
  14. $data['title'] = "Quality Health Safety Environment";
  15. $this->load->database();
  16. $data['data'] = $this->db->get('upload')->result();
  17. $this->load->view('create', $data, FALSE);
  18. }
  19.  
  20. public function create()
  21. {
  22. if (isset($_POST['submit'])){
  23. $this->form_validation->set_rules('name', 'Name', 'required');
  24.  
  25. $config['upload_path'] = './uploads/file';
  26. $config['allowed_types'] = 'pdf';
  27. $config['max_size'] = 2048;
  28. $config['encrypt_name'] = FALSE;
  29. // $config['max_height'] = 768;
  30. $this->load->library('upload', $config);
  31.  
  32. // //file 1
  33. // if(!empty($_FILES['file1']))
  34. // {
  35. // $this->upload->do_upload('file1');
  36. // $data1= $this->upload->data();
  37. // $file1 = $data1['file_name'];
  38.  
  39. // }
  40. //file2
  41. if(!empty($_FILES['file2']))
  42. {
  43. $this->upload->do_upload('file2');
  44. $data2= $this->upload->data();
  45. $file2 = $data2['file_name'];
  46.  
  47. }
  48.  
  49. if ($this->form_validation->run())
  50. {
  51. $name = $this->input->post('name', TRUE);
  52. $data = ['name'=>$name, 'file1'=>$file1, 'file2'=>$file2];
  53. $insert = $this->db->insert('upload', $data);
  54. if ($insert){
  55. $this->session->set_flashdata('pesan', '<div class="alert alert-succes"> Data Berhasil Disimpan </div>');
  56. redirect('upload');
  57. }
  58.  
  59.  
  60. }
  61. else
  62. {
  63. $this->index();
  64. }
  65.  
  66. }
  67. else
  68. {
  69. $this->index();
  70. }
  71. }
  72.  
  73. public function hapus($id)
  74. {
  75. $this->MDL_upload->hapus_data($id,'upload');
  76. redirect('Upload');
  77. }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement