Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dashboard.php(controller)
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- 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'] . '_thumb' . $finfo['file_ext'];
- $this->load->view('upload_success',$data);
- $this->load->view('dashboard',$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();
- }
- }
- dashboard.php(view)
- <?php
- // Load Menu
- $this->template->menu('dashboard');
- ?>
- <div id="container">
- <div class="upload">
- <?php echo form_open_multipart('index.php/dashboard/doUpload');//call controller
- echo form_upload('userfile');
- echo form_submit('upload','Upload Image');
- echo form_close();
- ?>
- </div>
- <div id="image">
- <img alt="your profile image" src="<?php echo base_url() . '/member/profile/' . $thumbnail_name;?>"/>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement