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 Upload extends CI_Controller {
  5.  
  6.  
  7.     public function index()
  8.     {
  9.         $list_file=array();
  10.         $dir = "uploaded_file/";
  11.  
  12.         // buka directory, dan baca isinya
  13.         if (is_dir($dir)){
  14.           if ($dh = opendir($dir)){
  15.             while (($file = readdir($dh)) !== false){
  16.                 $list_file[]=$file;
  17.             }
  18.             closedir($dh);
  19.           }
  20.         }
  21.  
  22.         $data['daftar_file']=$list_file;
  23.         $this->load->view('home',$data);
  24.     }
  25.    
  26.    
  27.     public function form(){
  28.         $data['page']='form_upload';
  29.         $this->load->view('home',$data);
  30.     }
  31.    
  32.     public function do_upload(){
  33.         $config['upload_path']   = './uploaded_file/';
  34.         $config['allowed_types'] = 'doc|docx|xls|xlsx|pdf|zip|rar';
  35.         $this->load->library('upload', $config);
  36.                
  37.                  if ( ! $this->upload->do_upload('file_nya')) {
  38.                     $data['error_upload'] = array('error' => $this->upload->display_errors());
  39.                     $this->session->set_userdata('status_upload',
  40.                     '<div class="alert alert-warning alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'.
  41.                     $data['error_upload']['error'].'</div>');
  42.                  }
  43.                    
  44.                  else {
  45.                     $this->session->set_userdata('status_upload','<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>File berhasil diupload</div>');
  46.                                                            
  47.                 }
  48.    
  49.             redirect(base_url());
  50.         }
  51.        
  52.     public function hapus($filenya){
  53.         $dir   = './uploaded_file/';
  54.         if(unlink($dir.$filenya)){
  55.         $this->session->set_userdata('status_hapus','<div class="alert alert-success alert-dismissible" role="alert">
  56.                                                             <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  57.                                                             File berhasil dihapus</div>');
  58.  
  59.         }  
  60.         redirect(base_url());
  61.     }  
  62. }