Advertisement
greyhat49

tulung CI kang...

Jun 2nd, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dashboard.php(controller)
  2. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3.  
  4. class Dashboard extends CI_Controller {
  5.  
  6.     function Dashboard()
  7.     {
  8.         parent::__construct();
  9.  
  10.         if(!$this->session->userdata('logged'))
  11.             redirect('login');
  12.     }
  13.  
  14.     public function index()
  15.     {
  16.         //$this->load->model('upload_model');
  17.         $data['page_title']  = "Dashboard";
  18.  
  19.         // Load View
  20.         $this->template->show('dashboard', $data);
  21.        
  22.         /*if($this->input->post('upload')){
  23.             $this->upload_model->do_upload();
  24.         }*/
  25.         //$this->load->view('upload_form');
  26.     }
  27.    
  28.     public function doUpload(){
  29.         $config = array(
  30.             'upload_path' => 'member/',
  31.             'allowed_types'=> 'png|jpg|jpeg',
  32.             'max_size'=> '1000',
  33.             'max_width'=> '1920',
  34.             'max_height'=> '1200'
  35.         );
  36.        
  37.         $this->load->library('upload', $config);
  38.         if(!$this->upload->do_upload()){
  39.             $error = array('error' => $this->upload->display_errors());
  40.            
  41.         }else{
  42.             $finfo = $this->upload->data();
  43.             echo '<pre>';
  44.             //dapatkan info file
  45.             print_r($finfo);
  46.             echo '<pre>';
  47.             $this->_createThumbnail($finfo['file_name']);
  48.            
  49.             $data['uploadInfo'] = $finfo;
  50.             $data['thumbnail_name'] = $finfo['raw_name'] . '_thumb' . $finfo['file_ext'];
  51.            
  52.             $this->load->view('upload_success',$data);
  53.             $this->load->view('dashboard',$data);
  54.         }
  55.        
  56.     }
  57.    
  58.     function _createThumbnail($filename){
  59.         $config = array(
  60.             'image_library' => 'gd2',
  61.             'source_image' => 'member/' . $filename,
  62.             'new_image' => 'member/profile',
  63.             'create_thumb' => 'true',
  64.             'maintain_ratio' => 'true',
  65.             'width' => 150,
  66.             'height' => 175
  67.         );
  68.         $this->load->library('image_lib',$config);
  69.         if(!$this->image_lib->resize())
  70.             echo $this->image_lib->display_errors();
  71.        
  72.     }
  73.    
  74.  
  75. }
  76.  
  77. dashboard.php(view)
  78. <?php
  79. // Load Menu
  80. $this->template->menu('dashboard');
  81. ?>
  82.  
  83. <div id="container">
  84.    
  85.     <div class="upload">
  86.         <?php echo form_open_multipart('index.php/dashboard/doUpload');//call controller
  87.             echo form_upload('userfile');
  88.             echo form_submit('upload','Upload Image');
  89.             echo form_close();
  90.         ?>
  91.     </div>
  92.    
  93.     <div id="image">
  94.         <img alt="your profile image" src="<?php echo base_url() . '/member/profile/' . $thumbnail_name;?>"/>
  95.     </div>
  96.    
  97.        
  98. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement