Advertisement
Guest User

Contrroller Upload

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