Advertisement
citstudio

Controller : Upload File Menggunakan CodeIgniter

Aug 19th, 2014
2,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class uploadfile extends CI_Controller {
  4.  
  5.     function __construct() {
  6.         parent::__construct();
  7.         $this->load->helper(array('form', 'url'));
  8.         $this->load->library('upload');
  9.     }
  10.  
  11.     function index() {
  12.         $this->load->view('uploadfile');
  13.     }
  14.  
  15.     function do_upload() {
  16.         $config = array(
  17.             'upload_path' => './resources/uploads'
  18.             , 'allowed_types' => 'gif|jpg|png'
  19.             , 'max_size' => '1000000000'
  20.             , 'max_width' => '2048'
  21.             , 'max_height' => '1024'
  22.         );
  23.  
  24.         $this->upload->initialize($config);
  25.  
  26.         $pic = '';
  27.  
  28.         if (isset($_FILES["userfile"]["name"])) {
  29.             if (!$this->upload->do_upload()) {
  30.                
  31.             } else {
  32.                 $tGambar = $this->upload->data();
  33.                 $pic = $tGambar["file_name"];
  34.             }
  35.         } else {
  36.             $pic = '';
  37.         }
  38.         print_r($pic);
  39.     }
  40.  
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement