Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if(! defined('BASEPATH')) exit('No direct script access allowed');
- /**
- *
- */
- class cuploadvideo extends CI_Controller
- {
- function __construct()
- {
- parent:: __construct();
- $this->load->model('muploadvideo');
- }
- function index(){
- $this->load->view('video');
- }
- // Tanggal hari ini
- function getTgl()
- {
- echo json_encode(array('Tanggal'=>date('Y/m/d')));
- }
- //end
- function random_string($length) {
- $key = '';
- $keys = array_merge(range('a', 'z'),range(0, 9));
- for ($i = 0; $i < $length; $i++) {
- $key .= $keys[array_rand($keys)];
- }
- return $key;
- }
- function upload_video(){
- $fd_name = $this->random_string(10);
- $fupload = array("folder"=>$fd_name,"fieldname"=>'file');
- $result= $this->muploadvideo->upload_video($fupload);
- $SQLData = array(
- "Kode" => $this->input->post('Kode') ,
- "Kode_Video" => $this->input->post('Kode_Video') ,
- "Judul" => $this->input->post('Judul') ,
- "Deskripsi" => $this->input->post('Deskripsi') ,
- "Tanggal" => $this->input->post('Tanggal') ,
- "name"=>$result['upload']['file_name'],
- "folder"=>$result['upload']['raw_name'],
- "Video"=>mysql_real_escape_string(file_get_contents($result['upload']['full_path']))
- );
- $insert = $this->db->insert('video',$SQLData);
- if($insert == true){
- echo json_encode(array("success"=>true,"text"=>"berhasil diupload","source"=>$result));
- }
- else{
- echo json_encode(array("success"=>false, "msg"=>msql_error()));
- }
- }
- //mendeskripsikan Grid pada image
- function gridvideo(){
- // jika ingin data ditampilkan di grid, alihkan url grid ke fungsi ini !!
- $page = isset($_POST['page']) ? intval($_POST['page']) : '1';
- $rows = isset($_POST['rows']) ? intval($_POST['rows']) : '10';
- $src = isset($_POST['src']) ? mysql_real_escape_string($_POST['src']) : '';
- $sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'id';
- $order = isset($_POST['order']) ? strval($_POST['order']) : 'ASC';
- $offset = ($page-1)*$rows;
- $grid = array();
- // ACTIVE RECORD UNTUK MEMANGGIL DATA store
- $this->db->select('*');
- $this->db->from('video');
- if($src != ""){ // |
- $data = array( // |
- "Id"=>$src, // |<-- digunakan sebagai filtrasi data, Aktif jika searching box pada view terisi
- "name"=>$src // |
- );
- $this->db->where($data);
- }
- $this->db->order_by($sort,$order);
- $this->db->limit($rows,$offset);
- $result = $this->db->get()->result();
- $grid['total'] = count($result);
- foreach ($result as $key => $value) {
- // $foldername = $result[$key]->folder;
- $result[$key]->img = '<img width="300px" height="300px" src="'.base_url('assets/uploads/video/'.$result[$key]->name).'" />';
- }
- $grid['rows'] = $result;
- echo json_encode($grid);
- }
- function update(){
- $Id = $this->input->post('Id',true);
- // GET LATEST IMAGE NAME FROM DATABASE
- $this->db->from('video');
- $this->db->where(array('Id'=>$Id));
- $get_imagename = $this->db->get()->result();
- $imgname = $get_imagename[0]->name;
- //################################
- /* -------------------------------------------------------------------------*/
- // REMOVE LATEST IMAGE FROM FOLDER
- if(file_exists('./assets/uploads/video/'.$imgname)){
- @unlink('./assets/uploads/video/'.$imgname);
- }
- // ################################
- /* -------------------------------------------------------------------------*/
- // REPLACE LATEST IMAGE WITH NEW IMAGE
- $fd_name = $this->random_string(10);
- $fupload = array("folder"=>$fd_name,"fieldname"=>'file');
- $result= $this->muploadvideo->upload_video($fupload);
- $SQLData = array(
- "Kode" => $this->input->post('Kode') ,
- "Kode_Video" => $this->input->post('Kode_Video') ,
- "Judul" => $this->input->post('Judul') ,
- "Deskripsi" => $this->input->post('Deskripsi') ,
- "Tanggal" => $this->input->post('Tanggal') ,
- "name"=>$result['upload']['file_name'],
- "folder"=>$result['upload']['raw_name'],
- "Video"=>mysql_real_escape_string(file_get_contents($result['upload']['full_path']))
- );
- $update = $this->db->update('video',$SQLData, array("Id"=>$Id));
- if($update == true){
- echo json_encode(array("success"=>true,"text"=>"berhasil diupload","source"=>$result));
- }
- else{
- echo json_encode(array("success"=>false, "msg"=>msql_error()));
- }
- // #################################################
- }
- // --------
- function remove(){
- $Id = $this->input->post('Id',true);
- // GET LATEST IMAGE NAME FROM DATABASE
- $this->db->from('video');
- $this->db->where(array('Id'=>$Id));
- $get_imagename = $this->db->get()->result();
- $imgname = $get_imagename[0]->name;
- //################################
- /* -------------------------------------------------------------------------*/
- // REMOVE LATEST IMAGE FROM FOLDER
- if(file_exists('./assets/uploads/video/'.$imgname)){
- @unlink('./assets/uploads/video/'.$imgname);
- }
- // ################################
- /* -------------------------------------------------------------------------*/
- // REPLACE LATEST IMAGE WITH NEW IMAGE
- $remove = $this->db->delete('video',array('Id'=>$Id));
- if ($remove == true){
- echo json_encode(array("success"=>true,"text"=>"berhasil dihapus"));
- }
- else {
- echo json_encode(array("success"=>false,"msg"=>msql_error()));
- }
- // #################################################
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement