Advertisement
Guest User

cuploadvideo

a guest
Sep 16th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?php if(! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. /**
  4. *
  5. */
  6. class cuploadvideo extends CI_Controller
  7. {
  8.    
  9.     function __construct()
  10.     {
  11.         parent:: __construct();
  12.         $this->load->model('muploadvideo');
  13.     }
  14.  
  15.     function index(){
  16.         $this->load->view('video');
  17.     }
  18.  
  19.  
  20. // Tanggal hari ini
  21.     function getTgl()
  22.     {
  23.         echo json_encode(array('Tanggal'=>date('Y/m/d')));
  24.     }
  25.    
  26.     //end
  27.  
  28.  
  29.     function random_string($length) {
  30.         $key = '';
  31.         $keys = array_merge(range('a', 'z'),range(0, 9));
  32.    
  33.         for ($i = 0; $i < $length; $i++) {
  34.             $key .= $keys[array_rand($keys)];
  35.         }
  36.    
  37.         return $key;
  38.     }
  39.  
  40.     function upload_video(){
  41.  
  42.         $fd_name = $this->random_string(10);
  43.        
  44.         $fupload = array("folder"=>$fd_name,"fieldname"=>'file');
  45.  
  46.         $result= $this->muploadvideo->upload_video($fupload);
  47.         $SQLData = array(
  48.                     "Kode" => $this->input->post('Kode') ,
  49.                     "Kode_Video" => $this->input->post('Kode_Video') ,
  50.                     "Judul" => $this->input->post('Judul') ,
  51.                     "Deskripsi" => $this->input->post('Deskripsi') ,
  52.                     "Tanggal" => $this->input->post('Tanggal') ,
  53.                     "name"=>$result['upload']['file_name'],
  54.                     "folder"=>$result['upload']['raw_name'],
  55.                     "Video"=>mysql_real_escape_string(file_get_contents($result['upload']['full_path']))
  56.                     );
  57.  
  58.         $insert = $this->db->insert('video',$SQLData);
  59.         if($insert == true){
  60.             echo json_encode(array("success"=>true,"text"=>"berhasil diupload","source"=>$result));
  61.         }
  62.         else{
  63.             echo json_encode(array("success"=>false, "msg"=>msql_error()));
  64.         }
  65.     }
  66.    
  67.    
  68.    
  69.  
  70.     //mendeskripsikan Grid pada image
  71.     function gridvideo(){
  72.         // jika ingin data ditampilkan di grid, alihkan url grid ke fungsi ini !!
  73.  
  74.         $page   = isset($_POST['page']) ? intval($_POST['page']) : '1';  
  75.         $rows   = isset($_POST['rows']) ? intval($_POST['rows']) : '10';  
  76.         $src    = isset($_POST['src']) ? mysql_real_escape_string($_POST['src']) : '';
  77.         $sort   = isset($_POST['sort']) ? strval($_POST['sort']) : 'id';  
  78.         $order  = isset($_POST['order']) ? strval($_POST['order']) : 'ASC';
  79.         $offset = ($page-1)*$rows;
  80.  
  81.         $grid = array();
  82.  
  83.         // ACTIVE RECORD UNTUK MEMANGGIL DATA store
  84.         $this->db->select('*');
  85.         $this->db->from('video');
  86.  
  87.         if($src != ""){                 // |
  88.             $data = array(              // |
  89.                         "Id"=>$src,     // |<-- digunakan sebagai filtrasi data, Aktif jika searching box pada view terisi
  90.                         "name"=>$src    // |
  91.                     );
  92.  
  93.             $this->db->where($data);
  94.         }
  95.  
  96.         $this->db->order_by($sort,$order);
  97.         $this->db->limit($rows,$offset);
  98.  
  99.         $result = $this->db->get()->result();
  100.  
  101.         $grid['total'] = count($result);
  102.  
  103.         foreach ($result as $key => $value) {
  104.             // $foldername = $result[$key]->folder;
  105.             $result[$key]->img = '<img width="300px" height="300px" src="'.base_url('assets/uploads/video/'.$result[$key]->name).'" />';
  106.         }
  107.         $grid['rows'] = $result;
  108.         echo json_encode($grid);
  109.     }
  110.    
  111.     function update(){
  112.         $Id = $this->input->post('Id',true);
  113.  
  114.         // GET LATEST IMAGE NAME FROM DATABASE
  115.         $this->db->from('video');
  116.         $this->db->where(array('Id'=>$Id));
  117.         $get_imagename = $this->db->get()->result();
  118.        
  119.         $imgname = $get_imagename[0]->name;
  120.         //################################
  121.         /* -------------------------------------------------------------------------*/
  122.         // REMOVE LATEST IMAGE FROM FOLDER
  123.         if(file_exists('./assets/uploads/video/'.$imgname)){
  124.             @unlink('./assets/uploads/video/'.$imgname);
  125.         }
  126.         // ################################
  127.         /* -------------------------------------------------------------------------*/
  128.         // REPLACE LATEST IMAGE WITH NEW IMAGE
  129.  
  130.         $fd_name = $this->random_string(10);
  131.  
  132.         $fupload = array("folder"=>$fd_name,"fieldname"=>'file');
  133.  
  134.         $result= $this->muploadvideo->upload_video($fupload);
  135.         $SQLData = array(
  136.                     "Kode" => $this->input->post('Kode') ,
  137.                     "Kode_Video" => $this->input->post('Kode_Video') ,
  138.                     "Judul" => $this->input->post('Judul') ,
  139.                     "Deskripsi" => $this->input->post('Deskripsi') ,
  140.                     "Tanggal" => $this->input->post('Tanggal') ,
  141.                     "name"=>$result['upload']['file_name'],
  142.                     "folder"=>$result['upload']['raw_name'],
  143.                     "Video"=>mysql_real_escape_string(file_get_contents($result['upload']['full_path']))
  144.                     );
  145.  
  146.         $update = $this->db->update('video',$SQLData, array("Id"=>$Id));
  147.         if($update == true){
  148.             echo json_encode(array("success"=>true,"text"=>"berhasil diupload","source"=>$result));
  149.         }
  150.         else{
  151.             echo json_encode(array("success"=>false, "msg"=>msql_error()));
  152.         }
  153.         // #################################################
  154.     }
  155.    
  156.     // --------
  157.    
  158.     function remove(){
  159.         $Id = $this->input->post('Id',true);
  160.  
  161.         // GET LATEST IMAGE NAME FROM DATABASE
  162.         $this->db->from('video');
  163.         $this->db->where(array('Id'=>$Id));
  164.         $get_imagename = $this->db->get()->result();
  165.        
  166.         $imgname = $get_imagename[0]->name;
  167.         //################################
  168.         /* -------------------------------------------------------------------------*/
  169.         // REMOVE LATEST IMAGE FROM FOLDER
  170.         if(file_exists('./assets/uploads/video/'.$imgname)){
  171.             @unlink('./assets/uploads/video/'.$imgname);
  172.         }
  173.         // ################################
  174.         /* -------------------------------------------------------------------------*/
  175.         // REPLACE LATEST IMAGE WITH NEW IMAGE
  176.        
  177.         $remove = $this->db->delete('video',array('Id'=>$Id));
  178.        
  179.         if ($remove == true){
  180.             echo json_encode(array("success"=>true,"text"=>"berhasil dihapus"));
  181.         }
  182.         else {
  183.             echo json_encode(array("success"=>false,"msg"=>msql_error()));
  184.         }
  185.         // #################################################
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement