Advertisement
GWibisono

upload neh

Sep 25th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Upload extends CI_Controller {
  3.  
  4.     function __construct()
  5.     {
  6.         parent::__construct();
  7.         $this->load->helper(array('form', 'url'));
  8.  
  9.        
  10.        
  11.  
  12.     }
  13.  
  14.     function index()
  15.     {
  16.         $this->load->view('upload_form', array('error' => ' ' ));
  17.     }
  18.  
  19.    
  20. public function do_upload()
  21. {
  22. $this->load->database();
  23.     $config['upload_path'] = './uploads/';
  24.         $config['allowed_types'] = 'gif|jpg|png';
  25.         $config['max_size'] = '100';
  26.         $config['max_width']  = '1024';
  27.         $config['max_height']  = '768';
  28.  
  29.        
  30.          $this->load->library('upload', $config);
  31.    
  32.      if ($this->upload->do_upload('userfile') == TRUE)
  33.      {
  34.          $data = $this->upload->data();
  35.          $nama_file = $data['file_name'];
  36.          $array = array('title' => 'Title', 'gambar' => $nama_file);
  37.      $this->db->insert('tes', $array);
  38.      }
  39.      else
  40.      {
  41.          $error = array('error' => $this->upload->display_errors());
  42.  
  43.             $this->load->view('upload_form', $error);
  44.      }
  45. }
  46.  
  47.  
  48.  
  49.    
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement