Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dashboard.php
- class Dashboard extends CI_Controller {
- function Dashboard()
- {
- parent::__construct();
- if(!$this->session->userdata('logged'))
- redirect('login');
- }
- public function index()
- {
- $this->load->model('upload_model');
- $data['page_title'] = "Dashboard";
- // Load View
- $this->template->show('dashboard', $data);
- if($this->input->post('upload')){
- $this->upload_model->do_upload();
- }
- $this->load->view('upload_form');
- }
- public function doUpload(){
- $config = array(
- 'upload_path' => 'member/',
- 'allowed_types'=> 'png|jpg|jpeg',
- 'max_size'=> '1000',
- 'max_width'=> '1920',
- 'max_height'=> '1200'
- );
- $this->load->library('upload', $config);
- if(!$this->upload->do_upload()){
- $error = array('error' => $this->upload->display_errors());
- }else{
- $finfo = $this->upload->data();
- echo '<pre>';
- //dapatkan info file
- print_r($finfo);
- echo '<pre>';
- $this->_createThumbnail($finfo['file_name']);
- $data['uploadInfo'] = $finfo;
- $data['thumbnail_name'] = $finfo['raw_name'] . '_profile' . $finfo['file_ext'];
- $this->load->view('upload_success',$data);
- }
- }
- function _createThumbnail($filename){
- $config = array(
- 'image_library' => 'gd2',
- 'source_image' => 'member/' . $filename,
- 'new_image' => 'member/profile',
- 'create_thumb' => 'true',
- 'maintain_ratio' => 'true',
- 'width' => 150,
- 'height' => 175
- );
- $this->load->library('image_lib',$config);
- if(!$this->image_lib->resize())
- echo $this->image_lib->display_errors();
- }
- }
- upload_model.php
- <?php
- class Upload_model extends CI_Model{
- //var $image_path;
- function Upload_model(){
- parent::__construct();
- //$image_path = realpath(APPPATH . './member');
- }
- public function do_upload()
- {
- $config = array(
- 'allowed_type' => 'gif|jpg|png|jpeg|JPG',
- 'upload_path' => './member/',
- 'max_size' => '1024',
- 'max_height' => '768'
- );
- $this->load->library('upload', $config);
- $this->upload->do_upload();
- $image_data = $this->upload->data();
- $config = array(
- 'source_image' => $image_data['full_path'],
- 'new_image' => './member/thumbs',
- 'maintain_ration' => true,
- 'width' => 150,
- 'height' => 100
- );
- $this->load->library('image_lib',$config);
- $this->image_lib->resize();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment