<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Upload extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('upload');
$this->load->helper(array('form', 'url'));
$this->load->database();
$this->load->library('form_validation');
}
public function index()
{
$this->load->view('index');
}
public function files()
{
$this->load->model('file_model','b');
$this->load->view('files');
}
public function upload_file()
{
$status = "";
$msg = "";
$filename = 'product_pic';
if(empty($_POST['title']))
{
$status = "error";
$title = "Please Enter Title";
}
if($status != "error")
{
$config['upload_path'] = 'img/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = true;
$this->upload->initialize($config);
if(!$this->upload->do_upload->('$filename'))
{
$status = 'error';
$msg = $this->upload->display_errors('','');
}
else
{
$this->load->model('file_model');
$data =$this->upload->data();
$file_id =$this->file_model->insert_file($data['file_name'],$_POST['title']);
if($file_id)
{
redirect('upload/index');
}
else
{
unlink($data['full_path']);
$status = "error";
$msg = "Please try again";
}
}
@unlink($_FILES[$filename]);
}
echo json_encode(array('status'=>$status,'msg'=>$msg));
}
}
?>
this is my controller file
on uploading image it showing error as follows
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Upload::$do_upload
Filename: controllers/upload.php
Line Number: 48
Backtrace:
File: D:\xampp\htdocs\picture\application\controllers\upload.php Line: 48 Function: _error_handler
File: D:\xampp\htdocs\picture\index.php Line: 315 Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/upload.php
Line Number: 48
Backtrace:
File: D:\xampp\htdocs\picture\application\controllers\upload.php Line: 48 Function: _error_handler
File: D:\xampp\htdocs\picture\index.php Line: 315 Function: require_once