I already load:
controllers/upload.php
PHP Code:
<?php
class Upload extends CI_Controller{
public function index()
{
$this->load->helper('form');
$this->load->view('main');
}
public function upload_image(){
$this->upload_model->do_upload(); //execute the upload function
}
}
?>
models/upload_model.php
PHP Code:
<?php
class User_model extends CI_Model{
var $original_path;
var $resized_path;
var $thumbs_path;
//initialize the path where you want to save your images
function __construct(){
parent::__construct();
//return the full path of the directory
//make sure these directories have read and write permessions
$this->original_path = realpath(APPPATH.'../uploads/original');
$this->resized_path = realpath(APPPATH.'../uploads/resized');
$this->thumbs_path = realpath(APPPATH.'../uploads/thumbs');
}
function do_upload(){
$this->load->library('image_lib');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png', //only accept these file types
'max_size' => 2048, //2MB max
'upload_path' => $this->original_path //upload directory
);
$this->load->library('upload', $config);
$image_data = $this->upload->data(); //upload the image
//your desired config for the resize() function
$config = array(
'source_image' => $image_data['full_path'], //path to the uploaded image
'new_image' => $this->resized_path, //path to
'maintain_ratio' => true,
'width' => 128,
'height' => 128
);
//this is the magic line that enables you generate multiple thumbnails
//you have to call the initialize() function each time you call the resize()
//otherwise it will not work and only generate one thumbnail
$this->image_lib->initialize($config);
$this->image_lib->resize();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->thumbs_path,
'maintain_ratio' => true,
'width' => 36,
'height' => 36
);
//here is the second thumbnail, notice the call for the initialize() function again
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
}
?>
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Upload::$upload_model
Filename: controllers/upload.php
Line Number: 15
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\upload\application\controllers\upload.php
Line: 15
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\upload\index.php
Line: 315
Function: require_once
Fatal error: Call to a member function do_upload() on null in
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\upload\application\controllers\upload.php on line
15
A PHP Error was encountered
Severity: Error
Message: Call to a member function do_upload() on null
Filename: controllers/upload.php
Line Number: 15
Backtrace:
upload.php
Line 15: $this->upload_model->do_upload(); //execute the upload function
That's the error! Can anyone help me fix the error?
" If I looks more intelligence please increase my reputation."