greyhat49

bingung dengan CI metode upload gan..

Jun 2nd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. dashboard.php
  2.  
  3. class Dashboard extends CI_Controller {
  4.  
  5.     function Dashboard()
  6.     {
  7.         parent::__construct();
  8.  
  9.         if(!$this->session->userdata('logged'))
  10.             redirect('login');
  11.     }
  12.  
  13.     public function index()
  14.     {
  15.         $this->load->model('upload_model');
  16.         $data['page_title']  = "Dashboard";
  17.  
  18.         // Load View
  19.         $this->template->show('dashboard', $data);
  20.        
  21.         if($this->input->post('upload')){
  22.             $this->upload_model->do_upload();
  23.         }
  24.         $this->load->view('upload_form');
  25.     }
  26.    
  27.     public function doUpload(){
  28.         $config = array(
  29.             'upload_path' => 'member/',
  30.             'allowed_types'=> 'png|jpg|jpeg',
  31.             'max_size'=> '1000',
  32.             'max_width'=> '1920',
  33.             'max_height'=> '1200'
  34.         );
  35.        
  36.         $this->load->library('upload', $config);
  37.         if(!$this->upload->do_upload()){
  38.             $error = array('error' => $this->upload->display_errors());
  39.            
  40.         }else{
  41.             $finfo = $this->upload->data();
  42.             echo '<pre>';
  43.             //dapatkan info file
  44.             print_r($finfo);
  45.             echo '<pre>';
  46.             $this->_createThumbnail($finfo['file_name']);
  47.            
  48.             $data['uploadInfo'] = $finfo;
  49.             $data['thumbnail_name'] = $finfo['raw_name'] . '_profile' . $finfo['file_ext'];
  50.            
  51.             $this->load->view('upload_success',$data);
  52.         }
  53.        
  54.     }
  55.    
  56.     function _createThumbnail($filename){
  57.         $config = array(
  58.             'image_library' => 'gd2',
  59.             'source_image' => 'member/' . $filename,
  60.             'new_image' => 'member/profile',
  61.             'create_thumb' => 'true',
  62.             'maintain_ratio' => 'true',
  63.             'width' => 150,
  64.             'height' => 175
  65.         );
  66.         $this->load->library('image_lib',$config);
  67.         if(!$this->image_lib->resize())
  68.             echo $this->image_lib->display_errors();
  69.        
  70.     }
  71.    
  72.  
  73. }
  74.  
  75.  
  76. upload_model.php
  77. <?php
  78.  
  79. class Upload_model extends CI_Model{
  80.     //var $image_path;
  81.    
  82.     function Upload_model(){
  83.         parent::__construct();
  84.        
  85.         //$image_path = realpath(APPPATH . './member');
  86.     }
  87.     public function do_upload()
  88.     {
  89.  
  90.     $config = array(
  91.         'allowed_type' => 'gif|jpg|png|jpeg|JPG',
  92.         'upload_path' => './member/',
  93.         'max_size' => '1024',
  94.         'max_height' => '768'
  95.     );
  96.    
  97.    
  98.     $this->load->library('upload', $config);
  99.     $this->upload->do_upload();
  100.    
  101.         $image_data = $this->upload->data();
  102.        
  103.         $config = array(
  104.             'source_image' => $image_data['full_path'],
  105.             'new_image' => './member/thumbs',
  106.             'maintain_ration' => true,
  107.             'width' => 150,
  108.             'height' => 100
  109.         );
  110.     $this->load->library('image_lib',$config);
  111.     $this->image_lib->resize();
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment