Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Welcome extends CI_Controller {
  5.  
  6.     function __construct(){
  7.         parent::__construct();
  8.         $this->load->library('upload');
  9.         $this->load->helper(['url','form']);
  10.     }
  11.  
  12.     public function index(){
  13.         $res = ['res'=>$this->db->get('tb_file')->result()];
  14.         $this->load->view('upload_file',$res);
  15.     }
  16.  
  17.     function store(){
  18.         $config['upload_path'] = './file/';
  19.         $config['allowed_types'] = 'pdf|php|html|js|xml|pptx|docx|xlsx|txt';
  20.         $config['file_name'] = 'file_'.time();
  21.         $this->upload->initialize($config);
  22.         if (!$this->upload->do_upload('file')) {
  23.             echo "<script>alert('Ulangi Lagi !!')
  24.                                 window.location='".base_url()."';
  25.                             </script>";
  26.         }else{
  27.             $file = $this->upload->data();
  28.             $this->db->insert('tb_file',[
  29.                 'nama_baru'=>$file['file_name'],
  30.                 'nama_ori'=>$file['client_name']
  31.             ]);
  32.             redirect(base_url());
  33.         }
  34.     }
  35.  
  36.     function edit($id){
  37.         $res = $this->db->get_where('tb_file',['id_file'=>$id])->result_array();
  38.         $this->load->view('edit_file',['res'=>$res]);
  39.     }
  40. }